Skip to content

Commit c75c606

Browse files
fix: error message from sass (#1231)
1 parent ce1ffc7 commit c75c606

8 files changed

+433
-94
lines changed

src/utils.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,15 @@ function errorFactory(error) {
889889
let message;
890890

891891
if (error.formatted) {
892-
message = error.formatted.replace(/^Error: /, "");
892+
message = error.formatted.replace(/^(.+)?Error: /, "");
893893
} else {
894894
// Keep original error if `sassError.formatted` is unavailable
895-
({ message } = error);
895+
message = (error.message || error.toString()).replace(/^(.+)?Error: /, "");
896896
}
897897

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

900+
obj.name = error.name;
900901
obj.stack = null;
901902

902903
return obj;

test/__snapshots__/loader.test.js.no-node-sass.snap

+46-46
Large diffs are not rendered by default.

test/__snapshots__/loader.test.js.snap

+46-46
Large diffs are not rendered by default.

test/__snapshots__/sassOptions-option.test.js.no-node-sass.snap

+144
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,78 @@ exports[`sassOptions option should ignore the "url" option ('sass-embedded', 'mo
12241224

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

1227+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `
1228+
[
1229+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1230+
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
1231+
]
1232+
`;
1233+
1234+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;
1235+
1236+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): errors 1`] = `
1237+
[
1238+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1239+
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
1240+
]
1241+
`;
1242+
1243+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;
1244+
1245+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
1246+
[
1247+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1248+
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
1249+
]
1250+
`;
1251+
1252+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;
1253+
1254+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
1255+
[
1256+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1257+
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
1258+
]
1259+
`;
1260+
1261+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;
1262+
1263+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `
1264+
[
1265+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1266+
arr.flatMap is not a function",
1267+
]
1268+
`;
1269+
1270+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;
1271+
1272+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): errors 1`] = `
1273+
[
1274+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1275+
arr.flatMap is not a function",
1276+
]
1277+
`;
1278+
1279+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;
1280+
1281+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
1282+
[
1283+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1284+
arr.flatMap is not a function",
1285+
]
1286+
`;
1287+
1288+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;
1289+
1290+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
1291+
[
1292+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1293+
arr.flatMap is not a function",
1294+
]
1295+
`;
1296+
1297+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;
1298+
12271299
exports[`sassOptions option should respect the "outputStyle"/"style" option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
12281300
"@charset "UTF-8";
12291301
@import "./file.css";
@@ -4388,6 +4460,78 @@ exports[`sassOptions option should work with custom scheme import ('sass-embedde
43884460

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

4463+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `
4464+
[
4465+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
4466+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
4467+
]
4468+
`;
4469+
4470+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;
4471+
4472+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): errors 1`] = `
4473+
[
4474+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
4475+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
4476+
]
4477+
`;
4478+
4479+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;
4480+
4481+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
4482+
[
4483+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
4484+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
4485+
]
4486+
`;
4487+
4488+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;
4489+
4490+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
4491+
[
4492+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
4493+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
4494+
]
4495+
`;
4496+
4497+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;
4498+
4499+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `
4500+
[
4501+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
4502+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
4503+
]
4504+
`;
4505+
4506+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;
4507+
4508+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): errors 1`] = `
4509+
[
4510+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
4511+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
4512+
]
4513+
`;
4514+
4515+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;
4516+
4517+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
4518+
[
4519+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
4520+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
4521+
]
4522+
`;
4523+
4524+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;
4525+
4526+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
4527+
[
4528+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
4529+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
4530+
]
4531+
`;
4532+
4533+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;
4534+
43914535
exports[`sassOptions option should work with the "functions" option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
43924536
"h2, h3, h4, h5 {
43934537
color: #08c;

test/__snapshots__/sassOptions-option.test.js.snap

+144
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,78 @@ exports[`sassOptions option should ignore the "url" option ('sass-embedded', 'mo
14041404

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

1407+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `
1408+
[
1409+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1410+
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
1411+
]
1412+
`;
1413+
1414+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;
1415+
1416+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): errors 1`] = `
1417+
[
1418+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1419+
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
1420+
]
1421+
`;
1422+
1423+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;
1424+
1425+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
1426+
[
1427+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1428+
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
1429+
]
1430+
`;
1431+
1432+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;
1433+
1434+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
1435+
[
1436+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1437+
method not found: 'get$iterator' (J.getInterceptor$ax(...).get$iterator is not a function)",
1438+
]
1439+
`;
1440+
1441+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;
1442+
1443+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `
1444+
[
1445+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1446+
arr.flatMap is not a function",
1447+
]
1448+
`;
1449+
1450+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;
1451+
1452+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): errors 1`] = `
1453+
[
1454+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1455+
arr.flatMap is not a function",
1456+
]
1457+
`;
1458+
1459+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;
1460+
1461+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
1462+
[
1463+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1464+
arr.flatMap is not a function",
1465+
]
1466+
`;
1467+
1468+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;
1469+
1470+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
1471+
[
1472+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
1473+
arr.flatMap is not a function",
1474+
]
1475+
`;
1476+
1477+
exports[`sassOptions option should output a normal error with the wrong "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;
1478+
14071479
exports[`sassOptions option should respect the "outputStyle"/"style" option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
14081480
"@charset "UTF-8";
14091481
@import "./file.css";
@@ -5054,6 +5126,78 @@ exports[`sassOptions option should work with custom scheme import ('sass-embedde
50545126

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

5129+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): errors 1`] = `
5130+
[
5131+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
5132+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
5133+
]
5134+
`;
5135+
5136+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;
5137+
5138+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): errors 1`] = `
5139+
[
5140+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
5141+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
5142+
]
5143+
`;
5144+
5145+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;
5146+
5147+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
5148+
[
5149+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
5150+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
5151+
]
5152+
`;
5153+
5154+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;
5155+
5156+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
5157+
[
5158+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
5159+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
5160+
]
5161+
`;
5162+
5163+
exports[`sassOptions option should work with the "fatalDeprecations" option ('dart-sass', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;
5164+
5165+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): errors 1`] = `
5166+
[
5167+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
5168+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
5169+
]
5170+
`;
5171+
5172+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'sass' syntax): warnings 1`] = `[]`;
5173+
5174+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): errors 1`] = `
5175+
[
5176+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
5177+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
5178+
]
5179+
`;
5180+
5181+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern' API, 'scss' syntax): warnings 1`] = `[]`;
5182+
5183+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): errors 1`] = `
5184+
[
5185+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
5186+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
5187+
]
5188+
`;
5189+
5190+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'sass' syntax): warnings 1`] = `[]`;
5191+
5192+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): errors 1`] = `
5193+
[
5194+
"ModuleBuildError: Module build failed (from ../src/cjs.js):
5195+
Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.",
5196+
]
5197+
`;
5198+
5199+
exports[`sassOptions option should work with the "fatalDeprecations" option ('sass-embedded', 'modern-compiler' API, 'scss' syntax): warnings 1`] = `[]`;
5200+
50575201
exports[`sassOptions option should work with the "functions" option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
50585202
"h2, h3, h4, h5 {
50595203
color: #08c;

test/sass/slash-div.sass

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.example
2+
color: red
3+
4+
a
5+
font-weight: (4/2)

test/sassOptions-option.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,44 @@ describe("sassOptions option", () => {
524524

525525
await close(compiler);
526526
});
527+
528+
if (isModernAPI) {
529+
it(`should output a normal error with the wrong "fatalDeprecations" option ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
530+
const testId = getTestId("language", syntax);
531+
const options = {
532+
implementation,
533+
api,
534+
sassOptions: {
535+
fatalDeprecations: "test",
536+
},
537+
};
538+
const compiler = getCompiler(testId, { loader: { options } });
539+
const stats = await compile(compiler);
540+
541+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
542+
expect(getErrors(stats)).toMatchSnapshot("errors");
543+
544+
await close(compiler);
545+
});
546+
547+
it(`should work with the "fatalDeprecations" option ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
548+
const testId = getTestId("slash-div", syntax);
549+
const options = {
550+
implementation,
551+
api,
552+
sassOptions: {
553+
fatalDeprecations: ["slash-div"],
554+
},
555+
};
556+
const compiler = getCompiler(testId, { loader: { options } });
557+
const stats = await compile(compiler);
558+
559+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
560+
expect(getErrors(stats)).toMatchSnapshot("errors");
561+
562+
await close(compiler);
563+
});
564+
}
527565
});
528566
});
529567
});

test/scss/slash-div.scss

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.example {
2+
color: red;
3+
4+
a {
5+
font-weight: (4/2);
6+
}
7+
}

0 commit comments

Comments
 (0)