Skip to content

Commit 63f15d3

Browse files
committed
[INTERNAL] npm t8r: Prevent re-throwing own errors
1 parent 9fd78dc commit 63f15d3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/translators/npm.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,16 @@ class NpmTranslator {
221221
log.verbose("Found module %s in that collection", moduleName);
222222
return modulePath;
223223
}
224-
throw new Error(`Could not find module ${moduleName} in collection ${pkg.name}`);
224+
throw new Error(`[npm translator] Could not find module ${moduleName} in collection ${pkg.name}`);
225225
}
226226
}
227-
throw new Error(`Could not locate module ${moduleName} via resolve logic ` +
227+
228+
throw new Error(`[npm translator] Could not locate module ${moduleName} via resolve logic ` +
228229
`(error: ${err.message}) or in a collection`);
230+
}, (err) => {
231+
throw new Error(
232+
`[npm translator] Failed to locate module ${moduleName} from ${basePath} - Error: ${err.message}`);
229233
});
230-
}).catch((err) => {
231-
throw new Error(
232-
`[npm translator] Failed to locate module ${moduleName} from ${basePath} - Error: ${err.message}`);
233234
});
234235
}
235236

test/lib/translators/npm.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ test("Error: missing package.json", async (t) => {
6363

6464
test("Error: missing dependency", async (t) => {
6565
const error = await t.throws(npmTranslator.generateDependencyTree(errApplicationAPath));
66-
t.is(error.message, "[npm translator] Failed to locate module library.xx from " +
67-
errApplicationAPath + " - Error: Could not locate " +
66+
t.is(error.message, "[npm translator] Could not locate " +
6867
"module library.xx via resolve logic (error: Cannot find module 'library.xx/package.json' from '" +
6968
errApplicationAPath + "') or in a collection");
7069
});

0 commit comments

Comments
 (0)