Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] minify: In case of error, include full resource path in the error messsage #1102

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/processors/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export default async function({
filename,
dbgFilename,
code,
resourcePath,
sourceMapOptions
}, taskUtil);
resource.setString(result.code);
Expand Down
4 changes: 3 additions & 1 deletion lib/processors/minifierWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ const copyrightCommentsAndBundleCommentPattern = /copyright|\(c\)(?:[0-9]+|\s+[0
* @param {string} parameters.filename
* @param {string} parameters.dbgFilename
* @param {string} parameters.code
* @param {string} parameters.resourcePath
* @param {object} parameters.sourceMapOptions
* @returns {Promise<undefined>} Promise resolving once minification of the resource has finished
*/
export default async function execMinification({
filename,
dbgFilename,
code,
resourcePath,
sourceMapOptions
}) {
try {
Expand All @@ -61,7 +63,7 @@ export default async function execMinification({
} catch (err) {
// Note: err.filename contains the debug-name
throw new Error(
`Minification failed with error: ${err.message} in file ${filename} ` +
`Minification failed with error: ${err.message} in file ${resourcePath} ` +
`(line ${err.line}, col ${err.col}, pos ${err.pos})`, {
cause: err
});
Expand Down
67 changes: 67 additions & 0 deletions test/lib/tasks/minify.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,70 @@ ${SOURCE_MAPPING_URL}=test.js.map`;
}
t.deepEqual(await resSourceMap.getString(), expectedSourceMap, "Correct source map content");
});

test.serial("integration: minify error", async (t) => {
const taskUtil = {
setTag: t.context.sinon.stub(),
STANDARD_TAGS: {
HasDebugVariant: "1️⃣",
IsDebugVariant: "2️⃣",
OmitFromBuildResult: "3️⃣"
},
registerCleanupTask: t.context.sinon.stub()
};
const {reader, workspace} = createWorkspace();
const content = `
// Top level return will cause a parsing error
return;`;
const testResource = resourceFactory.createResource({
path: "/resources/my/namespace/test.js",
string: content
});
await reader.write(testResource);

await t.throwsAsync(() => {
return minify({
workspace,
taskUtil,
options: {
pattern: "/resources/my/namespace/test.js",
omitSourceMapResources: true
}
});
}, {
message:
`Minification failed with error: 'return' outside of function in file ` +
`/resources/my/namespace/test.js (line 3, col 0, pos 48)`
}, `Threw with expected error message`);

// Ensure to call cleanup task so that workerpool is terminated - otherwise the test will time out!
const cleanupTask = taskUtil.registerCleanupTask.getCall(0).args[0];
await cleanupTask();
});


test.serial("integration: minify error (without taskUtil)", async (t) => {
const {reader, workspace} = createWorkspace();
const content = `
// Top level return will cause a parsing error
return;`;
const testResource = resourceFactory.createResource({
path: "/resources/my/namespace/test.js",
string: content
});
await reader.write(testResource);

await t.throwsAsync(() => {
return minify({
workspace,
options: {
pattern: "/resources/my/namespace/test.js",
omitSourceMapResources: true
}
});
}, {
message:
`Minification failed with error: 'return' outside of function in file ` +
`/resources/my/namespace/test.js (line 3, col 0, pos 48)`
}, `Threw with expected error message`);
});
Loading