-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Improve error when native helper gives empty output #6521
Improve error when native helper gives empty output #6521
Conversation
So this would be super useful, I was literally debugging an error like this just last night. However, is there a security risk here? Historically I thought we intentionally suppressed stderr output from the native helpers in prod because we don't control what they might output, and it could potentially include secrets. |
Fair concern. In my opinion, if a package manager is including secrets in its error output, that'd be a bug in the package manager (at least that's how Bundler & RubyGems treat it). If this is a concern though, we should review the whole codebase, because we're already including error output in other places. For example, whenever |
If native helper output is empty, an empty string is unparseable JSON and we end up getting an error about that, but no information about the underlying culprit. In this case, show the native error output, which is likely to contain something useful.
fa04a44
to
8fe91d3
Compare
Sorry for long comment and I know this has been in work in progress for a while, but I think it is worth revisiting. I was run down a rabbit hole tonight trying to figure out what exactly what was happening and causing the JSON parser error. I had to dig into the dependabot-core source code to figure out what was happening. Not intuitive or user friendly. If an error happens in the native subprocess helper, a more meaningful message can and should be raised with a valid error class associated with it. The proposed solution in this PR:
Is still problematic because the error class of JSON::ParserError in the resulting output message. The parser was not an error, it wasn't the cause of the issue, heck it had nothing to do with the issue, it was a red herring, because it was passed an empty string, which can and should be checked. I propose if stdout is empty or has a Json parse error, then process stderr and raise with a different error class. If worried about if the message has secrets, then the message could be as simple as a base message of "Error while running #{command}". We can mimic what is currently being done in the main branch for out of memory errors. If we attempt to detect some of the common ones, then we can append a much more meaningful message to the base message. For instance, 'command not found', 'Versionmismatch', and any other potentially common ones. (obviously, this would require some trial and error to get a few of the common ones). Below is untested, unlinted, non-ide written example of what I am trying to explain.
|
I get the idea and it makes sense. Rather than trying to parse empty output as JSON and rescue the parse error, we can detect the situation and raise something more explicit. Even if privacy of error messages not under our control is still a concern, we can still raise a more accurate error class than Feel free to raise a PR for this, I'll close this one for now since the privacy bit is unclear right now. |
If native helper output is empty, an empty string is unparseable JSON and we end up getting an error about that, but no information about the underlying culprit.
In this case, show the native error output, which is likely to contain something useful.
Before
After
Fix #4948