UNPKG

hardhat

Version:

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

47 lines 1.83 kB
import { createDebug } from "@nomicfoundation/hardhat-utils/debug"; import { isObject } from "@nomicfoundation/hardhat-utils/lang"; import { sendErrorTelemetry } from "./reporter.js"; const log = createDebug("hardhat:core:cli:telemetry:global-error-handlers"); function createUnhandledErrorListener(isPromiseRejection) { const description = isPromiseRejection ? "Unhandled promise rejection" : "Uncaught exception"; const mechanismType = isPromiseRejection ? "onunhandledrejection" : "onuncaughtexception"; async function listener(error) { log(description, error); const telemetryError = error instanceof Error ? error : new Error(isObject(error) && "message" in error && typeof error.message === "string" ? error.message : "Unknown error", { cause: error }); try { await sendErrorTelemetry(telemetryError, { unhandled: true, mechanismType, }); } catch (telemetryErrorReportingError) { log("Failed to send telemetry for unhandled error", telemetryErrorReportingError); } console.error(); console.error(`${description}:`); console.error(); console.error(error); process.exit(1); } return listener; } /** * Sets up global error handlers that report unhandled errors and promise * rejections if authorized by the user. */ export function setupGlobalUnhandledErrorHandlers() { log("Setting up global unhandled error handlers"); process.on("uncaughtException", createUnhandledErrorListener(false)); process.on("unhandledRejection", createUnhandledErrorListener(true)); } //# sourceMappingURL=global-error-handlers.js.map