Skip to content

Commit

Permalink
HouseKeeping: Moved errors to one place (#201)
Browse files Browse the repository at this point in the history
* added ExitError and ValidationError to errors package and replaced their usage across repository packages

* added changeset

* extend extendableError package instead of extending JS Error class, for better message logging

* updated changesets

* Maybe it's the cache?

* Try a thing
  • Loading branch information
ajaymathur authored and emmatown committed Oct 24, 2019
1 parent 51a0d76 commit 5ababa0
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .changeset/orange-eyes-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/cli": patch
"@changesets/config": patch
---

Updated to use the Error classes from the @changesets/errors package
6 changes: 6 additions & 0 deletions .changeset/rare-needles-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/errors": patch
---

- Added ExitError class and ValidationError class
- Extend extendable-error in our error classes instead of JS Error class due to better Error messages thrown
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "yarn.lock" }}
- v2-dependencies-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- v2-dependencies-
- run:
name: Install
command: yarn install --pure-lockfile
Expand Down Expand Up @@ -43,9 +43,9 @@ jobs:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "yarn.lock" }}
- v2-dependencies-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- v2-dependencies-
- run:
name: Install
command: yarn install --pure-lockfile
Expand All @@ -61,9 +61,9 @@ jobs:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "yarn.lock" }}
- v2-dependencies-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- v2-dependencies-
- run:
name: Install
command: yarn install --pure-lockfile
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@changesets/apply-release-plan": "^0.2.2",
"@changesets/assemble-release-plan": "^0.2.1",
"@changesets/config": "^0.2.1",
"@changesets/errors": "^0.1.0",
"@changesets/get-release-plan": "^0.1.3",
"@changesets/git": "^0.2.3",
"@changesets/logger": "^0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/publish/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import publishPackages from "./publishPackages";
import { ExitError } from "@changesets/errors";
import { error, log, success } from "@changesets/logger";
import * as git from "@changesets/git";
import { ExitError } from "../../utils/errors";
import { Config } from "@changesets/types";

function logReleases(pkgs: Array<{ name: string; newVersion: string }>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/publish/npm-utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ExitError } from "@changesets/errors";
import { error, info, warn } from "@changesets/logger";
import pLimit from "p-limit";
import chalk from "chalk";
import spawn from "spawndamnit";
import { askQuestion } from "../../utils/cli";
// @ts-ignore
import isCI from "is-ci";
import { ExitError } from "../../utils/errors";
import { TwoFactorState } from "../../utils/types";

const npmRequestLimit = pLimit(40);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import meow from "meow";
import { read } from "@changesets/config";
import { ExitError } from "@changesets/errors";
import { error } from "@changesets/logger";
import { Config } from "@changesets/types";
import fs from "fs-extra";
Expand All @@ -11,7 +12,6 @@ import add from "./commands/add";
import version from "./commands/version";
import publish from "./commands/publish";
import status from "./commands/status";
import { ExitError } from "./utils/errors";
import { CliOptions } from "./types";

const { input, flags } = meow(
Expand Down
7 changes: 0 additions & 7 deletions packages/cli/src/utils/errors.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"schema.json"
],
"dependencies": {
"@changesets/errors": "^0.1.0",
"@changesets/types": "^0.3.0",
"fs-extra": "^7.0.1"
},
Expand Down
15 changes: 5 additions & 10 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from "fs-extra";
import path from "path";
import { ValidationError } from "@changesets/errors";
import { Config, WrittenConfig, Workspace } from "@changesets/types";
import packageJson from "../package.json";

Expand Down Expand Up @@ -122,7 +123,10 @@ export let parse = (
}
}
if (messages.length) {
throw new ValidationError(messages);
throw new ValidationError(
`Some errors occurred when validating the changesets config:\n` +
messages.join("\n")
);
}

let config: Config = {
Expand All @@ -142,12 +146,3 @@ export let parse = (
};

export let defaultConfig = parse(defaultWrittenConfig, []);

export class ValidationError extends Error {
constructor(messages: Array<string>) {
super(
`Some errors occurred when validating the changesets config:\n` +
messages.join("\n")
);
}
}
5 changes: 4 additions & 1 deletion packages/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"main": "dist/errors.cjs.js",
"module": "dist/errors.esm.js",
"license": "MIT",
"repository": "https://github.com/changesets/changesets/tree/master/packages/errors"
"repository": "https://github.com/changesets/changesets/tree/master/packages/errors",
"dependencies": {
"extendable-error": "^0.1.5"
}
}
20 changes: 17 additions & 3 deletions packages/errors/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
export class GitError extends Error {
constructor(exitCode: number, message: string) {
super(`Error: Git - ${message}, exit code: ${exitCode}`);
import ExtendableError from "extendable-error";

export class GitError extends ExtendableError {
code: number;
constructor(code: number, message: string) {
super(`${message}, exit code: ${code}`);
this.code = code;
}
}

export class ValidationError extends ExtendableError {}

export class ExitError extends ExtendableError {
code: number;
constructor(code: number) {
super(`The process exited with code: ${code}`);
this.code = code;
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,11 @@ extend@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa"

extendable-error@^0.1.5:
version "0.1.5"
resolved "https://registry.yarnpkg.com/extendable-error/-/extendable-error-0.1.5.tgz#122308a7097bc89a263b2c4fbf089c78140e3b6d"
integrity sha1-EiMIpwl7yJomOyxPvwiceBQOO20=

external-editor@^2.0.4, external-editor@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.2.0.tgz#045511cfd8d133f3846673d1047c154e214ad3d5"
Expand Down

0 comments on commit 5ababa0

Please sign in to comment.