Skip to content

Commit 5ababa0

Browse files
ajaymathuremmatown
authored andcommitted
HouseKeeping: Moved errors to one place (changesets#201)
* 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
1 parent 51a0d76 commit 5ababa0

13 files changed

Lines changed: 54 additions & 30 deletions

File tree

‎.changeset/orange-eyes-march.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@changesets/cli": patch
3+
"@changesets/config": patch
4+
---
5+
6+
Updated to use the Error classes from the @changesets/errors package

‎.changeset/rare-needles-design.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@changesets/errors": patch
3+
---
4+
5+
- Added ExitError class and ValidationError class
6+
- Extend extendable-error in our error classes instead of JS Error class due to better Error messages thrown

‎.circleci/config.yml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ jobs:
88
- checkout
99
- restore_cache:
1010
keys:
11-
- v1-dependencies-{{ checksum "yarn.lock" }}
11+
- v2-dependencies-{{ checksum "yarn.lock" }}
1212
# fallback to using the latest cache if no exact match is found
13-
- v1-dependencies-
13+
- v2-dependencies-
1414
- run:
1515
name: Install
1616
command: yarn install --pure-lockfile
@@ -43,9 +43,9 @@ jobs:
4343
- checkout
4444
- restore_cache:
4545
keys:
46-
- v1-dependencies-{{ checksum "yarn.lock" }}
46+
- v2-dependencies-{{ checksum "yarn.lock" }}
4747
# fallback to using the latest cache if no exact match is found
48-
- v1-dependencies-
48+
- v2-dependencies-
4949
- run:
5050
name: Install
5151
command: yarn install --pure-lockfile
@@ -61,9 +61,9 @@ jobs:
6161
- checkout
6262
- restore_cache:
6363
keys:
64-
- v1-dependencies-{{ checksum "yarn.lock" }}
64+
- v2-dependencies-{{ checksum "yarn.lock" }}
6565
# fallback to using the latest cache if no exact match is found
66-
- v1-dependencies-
66+
- v2-dependencies-
6767
- run:
6868
name: Install
6969
command: yarn install --pure-lockfile

‎packages/cli/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@changesets/apply-release-plan": "^0.2.2",
2828
"@changesets/assemble-release-plan": "^0.2.1",
2929
"@changesets/config": "^0.2.1",
30+
"@changesets/errors": "^0.1.0",
3031
"@changesets/get-release-plan": "^0.1.3",
3132
"@changesets/git": "^0.2.3",
3233
"@changesets/logger": "^0.0.0",

‎packages/cli/src/commands/publish/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import publishPackages from "./publishPackages";
2+
import { ExitError } from "@changesets/errors";
23
import { error, log, success } from "@changesets/logger";
34
import * as git from "@changesets/git";
4-
import { ExitError } from "../../utils/errors";
55
import { Config } from "@changesets/types";
66

77
function logReleases(pkgs: Array<{ name: string; newVersion: string }>) {

‎packages/cli/src/commands/publish/npm-utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { ExitError } from "@changesets/errors";
12
import { error, info, warn } from "@changesets/logger";
23
import pLimit from "p-limit";
34
import chalk from "chalk";
45
import spawn from "spawndamnit";
56
import { askQuestion } from "../../utils/cli";
67
// @ts-ignore
78
import isCI from "is-ci";
8-
import { ExitError } from "../../utils/errors";
99
import { TwoFactorState } from "../../utils/types";
1010

1111
const npmRequestLimit = pLimit(40);

‎packages/cli/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import meow from "meow";
22
import { read } from "@changesets/config";
3+
import { ExitError } from "@changesets/errors";
34
import { error } from "@changesets/logger";
45
import { Config } from "@changesets/types";
56
import fs from "fs-extra";
@@ -11,7 +12,6 @@ import add from "./commands/add";
1112
import version from "./commands/version";
1213
import publish from "./commands/publish";
1314
import status from "./commands/status";
14-
import { ExitError } from "./utils/errors";
1515
import { CliOptions } from "./types";
1616

1717
const { input, flags } = meow(

‎packages/cli/src/utils/errors.ts‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎packages/config/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"schema.json"
1212
],
1313
"dependencies": {
14+
"@changesets/errors": "^0.1.0",
1415
"@changesets/types": "^0.3.0",
1516
"fs-extra": "^7.0.1"
1617
},

‎packages/config/src/index.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fs from "fs-extra";
22
import path from "path";
3+
import { ValidationError } from "@changesets/errors";
34
import { Config, WrittenConfig, Workspace } from "@changesets/types";
45
import packageJson from "../package.json";
56

@@ -122,7 +123,10 @@ export let parse = (
122123
}
123124
}
124125
if (messages.length) {
125-
throw new ValidationError(messages);
126+
throw new ValidationError(
127+
`Some errors occurred when validating the changesets config:\n` +
128+
messages.join("\n")
129+
);
126130
}
127131

128132
let config: Config = {
@@ -142,12 +146,3 @@ export let parse = (
142146
};
143147

144148
export let defaultConfig = parse(defaultWrittenConfig, []);
145-
146-
export class ValidationError extends Error {
147-
constructor(messages: Array<string>) {
148-
super(
149-
`Some errors occurred when validating the changesets config:\n` +
150-
messages.join("\n")
151-
);
152-
}
153-
}

0 commit comments

Comments
 (0)