Skip to content

Commit a08031c

Browse files
committed
Fix error printing for unknown errors
1 parent 0238f0b commit a08031c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

v-next/hardhat/src/internal/cli/error-handler.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import util from "node:util";
2+
13
import {
24
HardhatError,
35
HardhatPluginError,
@@ -84,7 +86,7 @@ export function printErrorMessages(
8486
/* eslint-disable-next-line @typescript-eslint/restrict-template-expressions
8587
-- As we don't know the type of error we are printing, we can't know if it
8688
has a `stack` property or not, so we print it as a string. */
87-
print(error instanceof Error ? `${error.stack}` : `${error}`);
89+
print(error instanceof Error ? `${error.stack}` : `${util.inspect(error)}`);
8890
if (postErrorStackTraceMessage !== undefined) {
8991
print("");
9092
print(postErrorStackTraceMessage);

v-next/hardhat/test/internal/cli/error-handler.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from "node:assert/strict";
22
import { beforeEach, describe, it } from "node:test";
3+
import util from "node:util";
34

45
import {
56
HardhatError,
@@ -278,7 +279,7 @@ describe("error-handler", () => {
278279
assert.equal(lines.length, 5);
279280
assert.equal(lines[0], chalk.red.bold(`An unexpected error occurred:`));
280281
assert.equal(lines[1], "");
281-
assert.equal(lines[2], `${error}`);
282+
assert.equal(lines[2], `${util.inspect(error)}`);
282283
assert.equal(lines[3], "");
283284
assert.equal(
284285
lines[4],

0 commit comments

Comments
 (0)