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

HouseKeeping: Moved errors to one place #201

Merged
merged 6 commits into from
Oct 24, 2019

Conversation

ajaymathur
Copy link
Contributor

Moved ExitError and ValidationError out from cli and config package respectively and updated the usage.

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2019

🦋 Changeset is good to go

Latest 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

@ajaymathur ajaymathur force-pushed the chore/move-errors-to-one-place branch from ab9b5c1 to 8872a0d Compare October 24, 2019 06:06
@codecov
Copy link

codecov bot commented Oct 24, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@51a0d76). Click here to learn what that means.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #201   +/-   ##
=========================================
  Coverage          ?   76.35%           
=========================================
  Files             ?       41           
  Lines             ?     1049           
  Branches          ?      228           
=========================================
  Hits              ?      801           
  Misses            ?      244           
  Partials          ?        4
Impacted Files Coverage Δ
packages/cli/src/commands/publish/index.ts 82.35% <ø> (ø)
packages/cli/src/commands/publish/npm-utils.ts 6.77% <ø> (ø)
packages/config/src/index.ts 100% <100%> (ø)
packages/errors/src/index.ts 50% <50%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51a0d76...1cdb85c. Read the comment docs.

@ajaymathur ajaymathur changed the title Moved errors to one place HouseKeeping: Moved errors to one place Oct 24, 2019
}

export class ExitError extends Error {
constructor(public code: number) {
Copy link
Member

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!


export class ValidationError extends Error {
constructor(message: string) {
super(`Validation Error: ${message}`);
Copy link
Member

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.

Suggested change
super(`Validation Error: ${message}`);
super(message);

Copy link
Contributor Author

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);
}

Copy link
Member

@emmatown emmatown Oct 24, 2019

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.

@ajaymathur
Copy link
Contributor Author

Strange the tests for failing in CI but pass in local.

Copy link
Member

@emmatown emmatown left a comment

Choose a reason for hiding this comment

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

Thanks!!

@emmatown emmatown merged commit 5ababa0 into master Oct 24, 2019
@emmatown emmatown deleted the chore/move-errors-to-one-place branch October 24, 2019 22:32
@github-actions github-actions bot mentioned this pull request Oct 24, 2019
@@ -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) {
Copy link
Contributor Author

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. 🙂

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

Successfully merging this pull request may close these issues.

None yet

2 participants