Skip to content

Commit e42af55

Browse files
authored
Merge pull request #7046 from NomicFoundation/sentry-trace
feat: report stack trace generation errors to sentry
2 parents 10f554d + 6ebaa3a commit e42af55

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

.changeset/fifty-roses-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Report stack trace generation errors to Sentry ([#7010](https://github.com/NomicFoundation/hardhat/issues/7010))

v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import debug from "debug";
4444
import { hexToBytes } from "ethereum-cryptography/utils";
4545
import { addr } from "micro-eth-signer";
4646

47+
import { sendErrorTelemetry } from "../../../cli/telemetry/sentry/reporter.js";
4748
import {
4849
EDR_NETWORK_REVERT_SNAPSHOT_EVENT,
4950
OPTIMISM_CHAIN_TYPE,
@@ -59,6 +60,7 @@ import {
5960
UnknownError,
6061
} from "../provider-errors.js";
6162

63+
import { EdrProviderStackTraceGenerationError } from "./stack-traces/stack-trace-generation-errors.js";
6264
import { createSolidityErrorWithStackTrace } from "./stack-traces/stack-trace-solidity-errors.js";
6365
import {
6466
isDebugTraceResult,
@@ -319,6 +321,10 @@ export class EdrProvider extends BaseProvider {
319321
try {
320322
stackTrace = edrResponse.stackTrace();
321323
} catch (e) {
324+
if (e instanceof Error) {
325+
await sendErrorTelemetry(new EdrProviderStackTraceGenerationError(e));
326+
}
327+
322328
log("Failed to get stack trace: %O", e);
323329
}
324330

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { CustomError } from "@nomicfoundation/hardhat-utils/error";
2+
3+
abstract class StackTraceGenerationError extends CustomError {}
4+
5+
export class EdrProviderStackTraceGenerationError extends StackTraceGenerationError {
6+
constructor(error: Error) {
7+
super("Failed to generate stack trace for the EDR provider", error);
8+
}
9+
}
10+
11+
export class SolidityTestStackTraceGenerationError extends StackTraceGenerationError {
12+
constructor(message: string) {
13+
super(
14+
"Failed to generate stack trace for the Solidity test",
15+
new Error(message),
16+
);
17+
}
18+
}

v-next/hardhat/src/internal/builtin-plugins/solidity-test/reporter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { TestResult } from "@ignored/edr-optimism";
88
import { bytesToHexString } from "@nomicfoundation/hardhat-utils/hex";
99
import chalk from "chalk";
1010

11+
import { sendErrorTelemetry } from "../../cli/telemetry/sentry/reporter.js";
12+
import { SolidityTestStackTraceGenerationError } from "../network-manager/edr/stack-traces/stack-trace-generation-errors.js";
1113
import { encodeStackTraceEntry } from "../network-manager/edr/stack-traces/stack-trace-solidity-errors.js";
1214

1315
import { formatArtifactId, formatLogs, formatTraces } from "./formatters.js";
@@ -210,6 +212,9 @@ export async function* testReporter(
210212
}
211213
break;
212214
case "UnexpectedError":
215+
await sendErrorTelemetry(
216+
new SolidityTestStackTraceGenerationError(stackTrace.errorMessage),
217+
);
213218
yield `Stack Trace Warning: ${chalk.grey(stackTrace.errorMessage)}\n`;
214219
break;
215220
case "UnsafeToReplay":

0 commit comments

Comments
 (0)