Skip to content

Commit

Permalink
modify function to check for error raised by external package
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDedominici committed Aug 7, 2024
1 parent bed832c commit 41d013f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 21 additions & 7 deletions v-next/hardhat/src/internal/cli/telemetry/sentry/anonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class Anonymizer {
public anonymizeErrorMessage(errorMessage: string): string {
errorMessage = this.#anonymizeMnemonic(errorMessage);

// the \\ before path.sep is necessary for this to work on windows
// Match path separators both for Windows and Unix
const pathRegex = /\S+[\/\\]\S+/g;

// for files that don't have a path separator
Expand Down Expand Up @@ -161,6 +161,10 @@ export class Anonymizer {
continue;
}

if (this.#errorRaisedByPackageToIgnore(frame.filename)) {
return false;
}

// we stop after finding either a hardhat file or a file from the user's
// project
if (this.#isHardhatFile(frame.filename)) {
Expand Down Expand Up @@ -197,15 +201,25 @@ export class Anonymizer {
}
}

#isHardhatFile(filename: string): boolean {
const totNodeModules = filename.split("node_modules").length - 1;
#errorRaisedByPackageToIgnore(filename: string): boolean {
const pkgsToIgnore: string[] = [
path.join("node_modules", "@random-npm-package"), // TODO: add real packages
];

const nomicFoundationPath = path.join("node_modules", "@nomicfoundation");
if (filename.startsWith(nomicFoundationPath) && totNodeModules === 1) {
return true;
const pkgs = filename.match(/node_modules[\/\\][^\/\\]+/g); // Match path separators both for Windows and Unix

if (pkgs === null) {
return false;
}

return false;
const errorSourcePkg = pkgs[pkgs.length - 1];

return pkgsToIgnore.includes(errorSourcePkg);
}

#isHardhatFile(filename: string): boolean {
const nomicFoundationPath = path.join("node_modules", "@nomicfoundation");
return filename.startsWith(nomicFoundationPath);
}

async #anonymizeExceptions(exceptions: Exception[]): Promise<Exception[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ describe("Anonymizer", () => {
"node_modules",
"@nomicfoundation",
"node_modules",
"@nomicfoundation-pkg2",
"node_modules",
"@random-npm-package",
"some-file.js",
),
Expand Down

0 comments on commit 41d013f

Please sign in to comment.