-
Notifications
You must be signed in to change notification settings - Fork 368
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
feat(errors): add more verbose errors #1798
Conversation
EditI just did not read the directions properly, and I was supposed to run How about the following language:
It still seems odd that the FaunaDB example would embed a call to |
The CLI detects different framework commands in package.json, and will throw if it detects `netlify dev` in the default script while running `netlify dev` in order to avoid recursively calling itself. By removing the `netlify dev` from the `start` and `dev` scripts and adjusting the CLI logic to recognize `netlify dev:exec` as distinct from `netlify:dev`, we can get this project working as expected. Also updates package.json dependencies. see also: netlify#26 netlify/cli#1798
The CLI detects different framework commands in package.json, and will throw if it detects `netlify dev` in the default script while running `netlify dev` in order to avoid recursively calling itself. By removing the `netlify dev` from the `start` and `dev` scripts and adjusting the CLI logic to recognize `netlify dev:exec` as distinct from `netlify:dev`, we can get this project working as expected. Also updates package.json dependencies. see also: netlify#26 netlify/cli#1798
Distinguishing between cli/src/detectors/utils/jsdetect.js Lines 87 to 89 in 6d53bbf
|
Hate to CC you @lindsaylevine but you're quickly becoming my Netlify buddy, I hope it's not a bother to bug you for a quick review whenever you get a minute 😅 I promise to slow down on the PRs, I just send them in to fix stuff as I find it! |
haha hey @ctjlewis!!!! no worries / no need to slow down as long as you can be patient with the team that owns the CLI (which, apologies, i am not on) 😁 |
No worries Lindsay, my bad for tagging you then! Also, after thinking about this some more, the " Will make those changes later today. |
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.
Hi @ctjlewis, you're on fire 🔥
I like the proposed changes in this PR (separating the errors and proper logging) but we have a PR that re-writes the way the current code works.
How about we incorporate those specific use cases into that PR?
Regarding error reporting, I wonder if logging inside the error ctor is the best approach.
We could use https://oclif.io/docs/error_handling#error-handling-in-the-catch-method to handle errors in a centralized location. WDYT?
I'll handle this as a part of #1704 |
Adding more verbose errors
This PR adds a
class InternalCliError extends Error {}
utility (which logs a stack trace and context object before throwing), and implements it in two locations.Required fields
Summary
I tried to run
netlify dev
in the netlify/netlify-faunadb-example project and received a confusing error that prevented me from moving forward. I dug into the CLI source again and modified the error logic to be clearer (and I now more or less understand why the CLI was throwing). This class can be used throughout the codebase as desired for throwing unrecoverable runtime errors.Test plan
This only modifies two existing errors at present, and should not require testing.
Changelog
Added clearer and more verbose error messages for a few edge cases.
Changes
Current behavior
In trying to use
netlify dev
with the netlify/netlify-faunadb-example project, I received the following error:This same error message would be provided in both cases below (no
possibleArgsArrs
, ornetlify dev
in a matching package.json script, as we see in netlify/netlify-faunadb-example).Proposed changes
My philosophy here was that if the CLI fails, it should log as much information as possible. The signature of the constructor is
InternalCliError(msg: string, context: object)
, and it will produce anError
with the same message as usual, but it will also useconsole.trace(...)
to pretty-print the context object provided at throw-time.With these changes merged, if no possible args array are found in
scanScripts
:And for the
netlify dev
error (which presents when a detector matches a script that contains a call tonetlify dev
, to ensure it does not recursively call itself):Thrown errors throughout the CLI could theoretically be replaced pretty easily, and should help with bug reports as it will be much easier to copy-paste details.
A separate error was also added for the
netlify dev
in package.json issue, as it would just bubble up to thepossibleArgsArr
error before.Footnotes
Super boring stylistic changes and comments were cleaned up, mostly just to save real estate and clarify the purpose of different statements. Some of the changes were required to silence the linter.