Skip to content

Commit

Permalink
Merge pull request #1196 from bdoner/fix/print-error-on-plugin-fail
Browse files Browse the repository at this point in the history
Add error to printed message when plugin fails to open
  • Loading branch information
sundowndev committed Jan 22, 2023
2 parents f03d6ae + 88c8b9d commit 8d7c622
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/remote/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package remote

import (
"fmt"
"github.com/sundowndev/phoneinfoga/v2/lib/number"
"os"
"plugin"

This comment has been minimized.

Copy link
@dana8-0

dana8-0 Jan 23, 2023

love

"github.com/sundowndev/phoneinfoga/v2/lib/number"
)

type Plugin interface {
Expand All @@ -25,7 +26,7 @@ func OpenPlugin(path string) error {

_, err := plugin.Open(path)
if err != nil {
return fmt.Errorf("given plugin %s is not valid", path)
return fmt.Errorf("given plugin %s is not valid: %v", path, err)
}

return nil
Expand Down
12 changes: 10 additions & 2 deletions lib/remote/scanner_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package remote

import (
"github.com/stretchr/testify/assert"
"fmt"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_ValidatePlugin_Errors(t *testing.T) {
invalidPluginAbsPath, err := filepath.Abs("testdata/invalid.so")
if err != nil {
assert.FailNow(t, "failed to get the absolute path of test file: %v", err)
}

testcases := []struct {
name string
path string
Expand All @@ -19,7 +27,7 @@ func Test_ValidatePlugin_Errors(t *testing.T) {
{
name: "test with invalid plugin",
path: "testdata/invalid.so",
wantErr: "given plugin testdata/invalid.so is not valid",
wantErr: fmt.Sprintf("given plugin testdata/invalid.so is not valid: plugin.Open(\"testdata/invalid.so\"): %s: file too short", invalidPluginAbsPath),
},
}

Expand Down

0 comments on commit 8d7c622

Please sign in to comment.