Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error to printed message when plugin fails to open #1196

Merged
merged 2 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"

"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