Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit ba0dc3d

Browse files
fix: Reduce the verbosity of error messages (#102)
1 parent a0c45b8 commit ba0dc3d

File tree

6 files changed

+122
-30
lines changed

6 files changed

+122
-30
lines changed

__snapshots__/compilation.spec.js

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__snapshots__/e2e.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ SyntaxError: /[cwd]/cypress/tests/e2e/compile-error.js: Unexpected token, expect
3333
| ^
3434
15 | })
3535
16 |
36-
@ multi ./cypress/tests/e2e/compile-error.js main[0]
3736
3837
This occurred while Cypress was compiling and bundling your test code. This is usually caused by:
3938

index.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,49 @@ const getDefaultWebpackOptions = (): webpack.Configuration => {
4141
}
4242
}
4343

44+
const replaceErrMessage = (err: Error, partToReplace: string, replaceWith = '') => {
45+
err.message = _.trim(err.message.replace(partToReplace, replaceWith))
46+
47+
if (err.stack) {
48+
err.stack = _.trim(err.stack.replace(partToReplace, replaceWith))
49+
}
50+
51+
return err
52+
}
53+
54+
const cleanModuleNotFoundError = (err: Error) => {
55+
const message = err.message
56+
57+
if (!message.includes('Module not found')) return err
58+
59+
const startIndex = message.lastIndexOf('resolve ')
60+
const endIndex = message.lastIndexOf(`doesn't exist`) + `doesn't exist`.length
61+
const partToReplace = message.substring(startIndex, endIndex)
62+
const newMessagePart = `Looked for and couldn't find the file at the following paths:`
63+
64+
return replaceErrMessage(err, partToReplace, newMessagePart)
65+
}
66+
67+
const cleanMultiNonsense = (err: Error) => {
68+
const message = err.message
69+
const startIndex = message.indexOf('@ multi')
70+
71+
if (startIndex < 0) return err
72+
73+
const partToReplace = message.substring(startIndex)
74+
75+
return replaceErrMessage(err, partToReplace)
76+
}
77+
78+
const quietErrorMessage = (err: Error) => {
79+
if (!err || !err.message) return err
80+
81+
err = cleanModuleNotFoundError(err)
82+
err = cleanMultiNonsense(err)
83+
84+
return err
85+
}
86+
4487
/**
4588
* Configuration object for this Webpack preprocessor
4689
*/
@@ -189,8 +232,11 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
189232
bundles[filePath] = latestBundle.promise
190233

191234
const rejectWithErr = (err: Error) => {
235+
err = quietErrorMessage(err)
236+
192237
// @ts-ignore
193238
err.filePath = filePath
239+
194240
debug(`errored bundling ${outputPath}`, err.message)
195241

196242
latestBundle.reject(err)

0 commit comments

Comments
 (0)