-
Notifications
You must be signed in to change notification settings - Fork 494
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
HouseKeeping: Moved errors to one place #201
Conversation
🦋 Changeset is good to goLatest commit: 1cdb85c We got this. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…eir usage across repository packages
ab9b5c1
to
8872a0d
Compare
Codecov Report
@@ Coverage Diff @@
## master #201 +/- ##
=========================================
Coverage ? 76.35%
=========================================
Files ? 41
Lines ? 1049
Branches ? 228
=========================================
Hits ? 801
Misses ? 244
Partials ? 4
Continue to review full report at Codecov.
|
packages/errors/src/index.ts
Outdated
} | ||
|
||
export class ExitError extends Error { | ||
constructor(public code: number) { |
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.
TIL about this syntax, thanks!
packages/errors/src/index.ts
Outdated
|
||
export class ValidationError extends Error { | ||
constructor(message: string) { | ||
super(`Validation Error: ${message}`); |
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'd rather have it pass the message directly because either one of two things will happen with the error, the error will be handled specially and some code can make it say that it's a validation error or the error will be logged and the name of error will be shown.
super(`Validation Error: ${message}`); | |
super(message); |
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.
Hey @mitchellhamilton,
If I follow your recommendation correctly it is because if we catch the error and log it, We don't want say it is validation error right?
Example:
try {
throw new ValidationError('Something something')
} catch (err) {
/**
* Will logging `Validation Error: Something something` be useful or `Something
* something`
**/
console.log(err);
}
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 just realized that extending Error doesn't show the right name but we can use extendable-error
to fix that and by doing that, when the error is logged, it'll look like this which includes the text ValidationError:
🦋 error { ValidationError: Something something
🦋 error at /Users/mitchell/projects/changesets/packages/cli/src/index.ts:61:9
🦋 error at Object.<anonymous> (/Users/mitchell/projects/changesets/packages/cli/src/index.ts:60:1)
🦋 error at Module._compile (internal/modules/cjs/loader.js:778:30)
🦋 error at Module._compile (/Users/mitchell/projects/changesets/node_modules/pirates/lib/index.js:99:24)
🦋 error at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
🦋 error at Object.newLoader (/Users/mitchell/projects/changesets/node_modules/pirates/lib/index.js:104:7)
🦋 error at Module.load (internal/modules/cjs/loader.js:653:32)
🦋 error at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
🦋 error name: 'ValidationError',
🦋 error _error:
🦋 error Error:
🦋 error at new ExtendableError (/Users/mitchell/projects/changesets/node_modules/extendable-error/bld/C:/Projects/extendable-error/src/index.ts:14:19)
🦋 error at new ValidationError (/Users/mitchell/projects/changesets/packages/cli/src/index.ts:56:5)
🦋 error at /Users/mitchell/projects/changesets/packages/cli/src/index.ts:61:9
🦋 error at Object.<anonymous> (/Users/mitchell/projects/changesets/packages/cli/src/index.ts:60:1)
🦋 error at Module._compile (internal/modules/cjs/loader.js:778:30)
🦋 error at Module._compile (/Users/mitchell/projects/changesets/node_modules/pirates/lib/index.js:99:24)
🦋 error at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
🦋 error at Object.newLoader (/Users/mitchell/projects/changesets/node_modules/pirates/lib/index.js:104:7)
🦋 error at Module.load (internal/modules/cjs/loader.js:653:32)
🦋 error at tryModuleLoad (internal/modules/cjs/loader.js:593:12) }
Also, now that I'm thinking about it, you can remove the constructor as well since inheriting ExtendableError's constructor will be fine here.
…or better message logging
Strange the tests for failing in CI but pass in local. |
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.
Thanks!!
@@ -1,15 +1,19 @@ | |||
import ExtendableError from "extendable-error"; | |||
|
|||
export class GitError extends ExtendableError { | |||
constructor(public code: number, message: string) { | |||
code: number; | |||
constructor(code: number, message: string) { |
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.
Wondering why did this happen. We can look at it later. 🙂
Moved
ExitError
andValidationError
out from cli and config package respectively and updated the usage.