-
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
Add defensive checks to prevent inscrutable error messages #4913
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,19 @@ module ResolvabilityErrors | |
GITHUB_REPO_REGEX = %r{github.com/[^:@]*} | ||
|
||
def self.handle(message, goprivate:) | ||
# TODO: currently this matches last. Instead, if more than one match, and they | ||
# aren't identical, then don't try to be clever with GitDependenciesNotReachable | ||
# but instead raise DependencyFileNotResolvable and report the whole error. | ||
# This would have resulted in a more obvious error message for #4625 | ||
mod_path = message.scan(GITHUB_REPO_REGEX).last | ||
if mod_path | ||
# TODO: if mod_path doesn't look like a URL, don't continue, but instead raise | ||
# DependencyFileNotResolvable and report the whole error. | ||
# This would have resulted in a more obvious error message for #4625 | ||
# How to implement this though? | ||
# * Ruby has no built-in URL parsing, and no great alternatives in https://stackoverflow.com/q/1805761/770425... | ||
# Not sure what Dependabot team policy is on using 3rd-party gems? | ||
# Alternatively a basic sanity check of "it should not contain whitespace" may suffice for now... ?? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we expect a URL here or just the module path? If it's the path we could use some of the basic character checks from https://pkg.go.dev/golang.org/x/mod/module#CheckImportPath / https://pkg.go.dev/golang.org/x/mod/module#CheckPath as a start? Agree we just need a simple defensive check rather than a robust validation here. |
||
raise Dependabot::DependencyFileNotResolvable, message unless mod_path | ||
|
||
# Module not found on github.com - query for _any_ version to know if it | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wasn't 100% sure on this... I could see a case where a multi-line error string may have multiple URLs, and the last one is indeed the proper one to match on...
But given that
GitDependenciesNotReachable
tells the user that Dependabot can't reach the repo and to update their access creds, that's a fairly opinionated solution...IMO I'd only want to report that if 110% sure that's the issue, otherwise surface the whole error message and let the user diagnose the issue.
(I assume
DependencyFileNotResolvable
reports the message to the end user... if it just hides it in logs that only Dependabot devs can see, then that's not so helpful either.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see these cases as most useful to raise
GitDependenciesNotReachable
.Do we have examples of what multiple URLs look like in this error message handy? I imagine this could get tricky if you had a failing indirect dependency on another host that came from one of your direct github dependencies.