Skip to content

Commit 2c1b55d

Browse files
committed
improve AggregateError message
1 parent e0e29b9 commit 2c1b55d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

bin/query.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default async function run(args?: string[]): Promise<void> {
5555
await writeFile(cachePath, JSON.stringify(results, replace));
5656
console.log(join(values.root, cachePath));
5757
} catch (error) {
58-
console.error(String(error));
58+
console.error(getErrorMessage(error));
5959
process.exit(1);
6060
}
6161
}
@@ -65,3 +65,12 @@ export default async function run(args?: string[]): Promise<void> {
6565
function replace(this: {[key: string]: unknown}, key: string, value: unknown): unknown {
6666
return this[key] instanceof Date ? Date.prototype.toJSON.call(this[key]) : value;
6767
}
68+
69+
function getErrorMessage(error: unknown): string {
70+
return error instanceof Error &&
71+
"errors" in error && // AggregateError
72+
Array.isArray(error.errors) &&
73+
error.errors.length > 0
74+
? String(error.errors[0])
75+
: String(error);
76+
}

0 commit comments

Comments
 (0)