Skip to content

Commit d49b106

Browse files
fixed up titles and some bad assumptions about errors prop
1 parent d2d3044 commit d49b106

File tree

10 files changed

+67
-18
lines changed

10 files changed

+67
-18
lines changed

dist/wait-in-parallel.cjs.js

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/wait-in-parallel.es.js

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@
3838
"@types/chance": "^1.0.0",
3939
"@types/faker": "^4.1.2",
4040
"@types/handlebars": "^4.0.37",
41+
"@types/inquirer": "^0.0.41",
4142
"@types/js-yaml": "^3.11.1",
4243
"@types/lodash": "^4.14.108",
44+
"@types/lodash.first": "^3.0.5",
4345
"@types/mocha": "^5.2.0",
4446
"@types/node": "^8.10.0",
4547
"@types/rimraf": "^2.0.2",
46-
"@types/inquirer": "^0.0.41",
4748
"async-shelljs": "^0.1.2",
4849
"bili": "^3.1.0",
4950
"chai": "^4.1.2",

src/ParallelError.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { IDictionary } from "common-types";
22
import { Parallel } from "./index";
3+
const first = require("lodash.first");
4+
5+
/**
6+
* The first key in a Hash/Dictionary
7+
*/
8+
function firstKey<T = any>(dictionary: IDictionary<T>) {
9+
return first(Object.keys(dictionary));
10+
}
311

412
export class ParallelError<T = any> extends Error {
513
name = "ParallelError";
@@ -59,7 +67,9 @@ export class ParallelError<T = any> extends Error {
5967
};
6068

6169
return errors[f].name === "ParallelError"
62-
? `\n - ${f} [ParallelError { ${inspect(errors[f] as ParallelError)} }]`
70+
? `\n - ${f} [ParallelError ${context.title ? context.title : ""} { ${inspect(
71+
errors[f] as ParallelError
72+
)} }]`
6373
: `\n - ${f} [${
6474
errors[f].code ? `${errors[f].name}:${errors[f].code}` : errors[f].name
6575
} ${getFirstErrorLocation(errors[f].stack)}]`;
@@ -69,9 +79,11 @@ export class ParallelError<T = any> extends Error {
6979
this.message = `${context.title ? context.title + ": " : ""}${
7080
context._get("failed").length
7181
} of ${failed.length +
72-
successful.length} parallel tasks failed.\nTasks failing were: ${errorSummary}.\n\nFirst error message was: ${
73-
errors[0].message
74-
}`;
82+
successful.length} parallel tasks failed.\nTasks failing were: ${errorSummary}."`;
83+
this.message +=
84+
Object.keys(errors).length > 0
85+
? `\n\nFirst error message was: ${(this, errors[firstKey(errors)].message)}`
86+
: "";
7587
this.errors = errors;
7688
this.failed = failed;
7789
this.successful = successful;

test/basics-spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable:no-implicit-dependencies
2-
import Parallel, { IParallelFailureNotification } from "../src/index";
2+
import { Parallel, IParallelFailureNotification } from "../src/index";
33
import * as chai from "chai";
44
import { wait } from "common-types";
55
import * as helpers from "./testing/helpers";
@@ -39,7 +39,7 @@ describe("Basics →", () => {
3939
});
4040

4141
it("using get() utility function for invalid property throws error", async () => {
42-
const obj = Parallel.create();
42+
const obj = Parallel.create("test title");
4343
try {
4444
obj._get("foobar");
4545
throw new Error("Foobar is not a valid get property");
@@ -127,21 +127,23 @@ describe("Basics →", () => {
127127
};
128128

129129
const masterError = async () => {
130-
const p = Parallel.create()
130+
const p = Parallel.create("Master Error")
131131
.add("f3", f3)
132132
.add("f4", f4);
133133
await p.isDone();
134134
};
135135

136136
try {
137-
const p = Parallel.create()
137+
const p = Parallel.create("Nested Errors")
138138
.add("success", s1)
139139
.add("fail1", f1)
140140
.add("fail2", f2)
141141
.add("fail4", masterError);
142142
await p.isDone();
143143
throw new Error("Error should have been thrown");
144144
} catch (e) {
145+
console.log(e);
146+
145147
expect(e.message).to.include("fail1 [FictitiousError @");
146148
expect(e.message).to.include("fail4 [ParallelError { f3");
147149
}

test/done-as-array-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable:no-implicit-dependencies
2-
import Parallel, { IParallelFailureNotification } from "../src/index";
2+
import { Parallel, IParallelFailureNotification } from "../src/index";
33
import * as chai from "chai";
44
import { wait } from "common-types";
55
import * as helpers from "./testing/helpers";

test/fail-fast-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable:no-implicit-dependencies
2-
import Parallel, { IParallelFailureNotification } from "../src/index";
2+
import { Parallel, IParallelFailureNotification } from "../src/index";
33
import * as chai from "chai";
44
import { wait } from "common-types";
55
import { ParallelError } from "../src/ParallelError";

test/fail-slow-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable:no-implicit-dependencies
2-
import Parallel, { IParallelFailureNotification } from "../src/index";
2+
import { Parallel, IParallelFailureNotification } from "../src/index";
33
import * as chai from "chai";
44
import { wait } from "common-types";
55
import { ParallelError } from "../src/ParallelError";

test/timeout-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable:no-implicit-dependencies
2-
import Parallel, { IParallelFailureNotification } from "../src/index";
2+
import { Parallel, IParallelFailureNotification } from "../src/index";
33
import * as chai from "chai";
44
import { wait } from "common-types";
55
import { ParallelError } from "../src/ParallelError";

yarn.lock

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,18 @@
633633
version "3.11.1"
634634
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.11.1.tgz#ac5bab26be5f9c6f74b6b23420f2cfa5a7a6ba40"
635635

636+
"@types/lodash.first@^3.0.5":
637+
version "3.0.5"
638+
resolved "https://registry.yarnpkg.com/@types/lodash.first/-/lodash.first-3.0.5.tgz#e6446422d480272af77a374dd4139548c3f7ce4d"
639+
integrity sha512-I4a7KdfXAeD+l3T9IYlIRUCYEIhoWE4BttoHBpOcw6tJPXGsJTBBEljce4c0UZgkAiEDym9XEIsgiD/puXGTCw==
640+
dependencies:
641+
"@types/lodash" "*"
642+
643+
"@types/lodash@*":
644+
version "4.14.121"
645+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.121.tgz#9327e20d49b95fc2bf983fc2f045b2c6effc80b9"
646+
integrity sha512-ORj7IBWj13iYufXt/VXrCNMbUuCTJfhzme5kx9U/UtcIPdJYuvPDUAlHlbNhz/8lKCLy9XGIZnGrqXOtQbPGoQ==
647+
636648
"@types/lodash@^4.14.108":
637649
version "4.14.109"
638650
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.109.tgz#b1c4442239730bf35cabaf493c772b18c045886d"
@@ -1466,10 +1478,15 @@ commander@~2.13.0:
14661478
version "2.13.0"
14671479
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"
14681480

1469-
common-types@^1.1.0, common-types@^1.7.21:
1481+
common-types@^1.1.0:
14701482
version "1.7.33"
14711483
resolved "https://registry.yarnpkg.com/common-types/-/common-types-1.7.33.tgz#efa03d07d39aa22ed6fdc1452cd5011ce033402e"
14721484

1485+
common-types@^1.9.6s:
1486+
version "1.9.6"
1487+
resolved "https://registry.yarnpkg.com/common-types/-/common-types-1.9.6.tgz#ec94d6466e4bd2876fb734297d7f8abf665f4aa3"
1488+
integrity sha512-JyMYuxDJgrhgqBh1D+A0C7ghCiVw+vxrxwNt/FcgoMhGzh/KqX8vOVwQBA6no5onsXAYcepAwUxrYYjpvrBChA==
1489+
14731490
commondir@^1.0.1:
14741491
version "1.0.1"
14751492
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
@@ -2693,6 +2710,7 @@ locate-path@^2.0.0:
26932710
lodash.first@^3.0.0:
26942711
version "3.0.0"
26952712
resolved "https://registry.yarnpkg.com/lodash.first/-/lodash.first-3.0.0.tgz#5dae180d7f818ee65fc5b210b104a7bbef98a16a"
2713+
integrity sha1-Xa4YDX+BjuZfxbIQsQSnu++YoWo=
26962714

26972715
lodash.last@^3.0.0:
26982716
version "3.0.0"

0 commit comments

Comments
 (0)