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 more helpful message on plugin setup failure #223

Merged
merged 8 commits into from
Dec 5, 2022

Conversation

swenson
Copy link
Contributor

@swenson swenson commented Dec 2, 2022

The current error message shown when a plugin does not respond correctly can be obtuse to the end user of, for example, Vault.

Here, we add potential reasons why the plugin did not respond correctly, and some additional debugging information (provided as a best effort) including the CPU architecture that the plugin was compiled for, the current CPU architecture, and the permissions of the plugin. Hopefully this will help users diagnose why their plugin is not loading.

We also added a testdata/ directory that is optionally populated with executables in various formats to help test the additional debugging information. The binaries are over 1 MB each though, so are not checked in, and the test will be skipped if they have not been compiled.

The error message comes out looking like:

    err: Unrecognized remote plugin message: something invalid here
        This usually means
          the plugin was not compiled for this architecture,
          the plugin is missing dynamic-link libraries necessary to run,
          the plugin is not readable by this process, or
          the plugin was compiled with an incompatible version of the go-plugin protocol

        Additional notes about plugin:  Path: /var/folders/jb/4vzywqts2gl49jvwp0pz9dsc0000gq/T/go-build2701257428/b001/go-plugin.test
          Mode: -rwxr-xr-x
          MachO architecture: CpuArm64 (current architecture: arm64)

The current error message shown when a plugin does not respond correctly
can be obtuse to the end user of, for example, Vault.

Here, we add potential reasons why the plugin did not respond correctly,
and some additional debugging information (provided as a best effort)
including the CPU architecture that the plugin was compiled for,
the current CPU architecture, and the permissions of the plugin.
Hopefully this will help users diagnose why their plugin is not loading.

We also added a `testdata/` directory that is optionally populated
with executables in various formats to help test the additional
debugging information. The binaries are over 1 MB each though, so
are not checked in, and the test will be skipped if they have not been
compiled.
client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
Christopher Swenson and others added 3 commits December 2, 2022 15:24
Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>
Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great 👍 left a few thoughts for minor improvements.

client.go Outdated Show resolved Hide resolved
client.go Show resolved Hide resolved
testdata/README.md Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
swenson and others added 4 commits December 5, 2022 09:04
Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
"Unrecognized remote plugin message: %s\n\n"+
"This usually means that the plugin is either invalid or simply\n"+
"needs to be recompiled to support the latest protocol.", line)
err = fmt.Errorf(unrecognizedRemotePluginMessage, line, additionalNotesAboutCommand(cmd.Path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: Given the scope of usage of this library, and the fact we have a levelled logger available, would it potentially make sense to log the additional notes to debug level instead, and include a note about the availability of debug logs in the error message? I can definitely see the appeal of just having all the information available right there in the error message, and I can also see the possibility for grumbles about verboseness (which I personally don't sympathise with too much), so I'm genuinely undecided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by returning an error message, we give the caller the option to log and at what level. They certainly might perform an action based on the remote plugin message in the first line. I think I prefer it as is.

Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a question but I am happy with either direction, so LGTM 👍

Copy link
Contributor

@fairclothjm fairclothjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@swenson
Copy link
Contributor Author

swenson commented Dec 5, 2022

Thanks!

@swenson swenson merged commit 5ecc4fb into master Dec 5, 2022
@swenson swenson deleted the vault-9832/better-plugin-error-message branch December 5, 2022 22:04
notes += "\nAdditional notes about plugin:\n"
notes += fmt.Sprintf(" Path: %s\n", path)
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode())
statT, ok := stat.Sys().(*syscall.Stat_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

this does not compile on Windows:

Error: C:\Users\runneradmin\go\pkg\mod\github.com\hashicorp\go-plugin@v1.4.7\client.go:512:36: undefined: syscall.Stat_t

https://github.com/drakkan/sftpgo/actions/runs/3641265803/jobs/6146996350

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants