Skip to content

Commit

Permalink
fix: error message from sass (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Sep 20, 2024
1 parent ce1ffc7 commit c75c606
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 94 deletions.
5 changes: 3 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,14 +889,15 @@ function errorFactory(error) {
let message;

if (error.formatted) {
message = error.formatted.replace(/^Error: /, "");
message = error.formatted.replace(/^(.+)?Error: /, "");
} else {
// Keep original error if `sassError.formatted` is unavailable
({ message } = error);
message = (error.message || error.toString()).replace(/^(.+)?Error: /, "");
}

const obj = new Error(message, { cause: error });

obj.name = error.name;
obj.stack = null;

return obj;
Expand Down
92 changes: 46 additions & 46 deletions test/__snapshots__/loader.test.js.no-node-sass.snap

Large diffs are not rendered by default.

92 changes: 46 additions & 46 deletions test/__snapshots__/loader.test.js.snap

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions test/__snapshots__/sassOptions-option.test.js.no-node-sass.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,78 @@ exports[`sassOptions option should ignore the "url" option ('sass-embedded', 'mo

exports[`sassOptions option should ignore the "url" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
arr.flatMap is not a function",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
arr.flatMap is not a function",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
arr.flatMap is not a function",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
arr.flatMap is not a function",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should respect the "outputStyle"/"style" option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
"@charset "UTF-8";
@import "./file.css";
Expand Down Expand Up @@ -4388,6 +4460,78 @@ exports[`sassOptions option should work with custom scheme import ('sass-embedde

exports[`sassOptions option should work with custom scheme import ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "functions" option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
"h2, h3, h4, h5 {
color: #08c;
Expand Down
144 changes: 144 additions & 0 deletions test/__snapshots__/sassOptions-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,78 @@ exports[`sassOptions option should ignore the "url" option ('sass-embedded', 'mo

exports[`sassOptions option should ignore the "url" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
arr.flatMap is not a function",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
arr.flatMap is not a function",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
arr.flatMap is not a function",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
arr.flatMap is not a function",
]
`;

exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should respect the "outputStyle"/"style" option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
"@charset "UTF-8";
@import "./file.css";
Expand Down Expand Up @@ -5054,6 +5126,78 @@ exports[`sassOptions option should work with custom scheme import ('sass-embedde

exports[`sassOptions option should work with custom scheme import ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
[
"ModuleBuildError: Module build failed (from ../src/cjs.js):
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
]
`;

exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;

exports[`sassOptions option should work with the "functions" option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
"h2, h3, h4, h5 {
color: #08c;
Expand Down
5 changes: 5 additions & 0 deletions test/sass/slash-div.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.example
color: red

a
font-weight: (4/2)
38 changes: 38 additions & 0 deletions test/sassOptions-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,44 @@ describe("sassOptions option", () => {

await close(compiler);
});

if (isModernAPI) {
it(`should output a normal error with the wrong "fatalDeprecations" option ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
const testId = getTestId("language", syntax);
const options = {
implementation,
api,
sassOptions: {
fatalDeprecations: "test",
},
};
const compiler = getCompiler(testId, { loader: { options } });
const stats = await compile(compiler);

expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");

await close(compiler);
});

it(`should work with the "fatalDeprecations" option ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
const testId = getTestId("slash-div", syntax);
const options = {
implementation,
api,
sassOptions: {
fatalDeprecations: ["slash-div"],
},
};
const compiler = getCompiler(testId, { loader: { options } });
const stats = await compile(compiler);

expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");

await close(compiler);
});
}
});
});
});
7 changes: 7 additions & 0 deletions test/scss/slash-div.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.example {
color: red;

a {
font-weight: (4/2);
}
}

0 comments on commit c75c606

Please sign in to comment.