Skip to content

Commit 0d8e150

Browse files
authored
Improve error messages (#429)
Most of these are just removing periods which are redundant because the underlying call already adds one.
1 parent e2cfd3e commit 0d8e150

9 files changed

Lines changed: 23 additions & 23 deletions

File tree

lib/src/compiler/async.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class AsyncCompiler {
9898
/** Guards against using a disposed compiler. */
9999
private throwIfDisposed(): void {
100100
if (this.disposed) {
101-
throw utils.compilerError('Async compiler has already been disposed.');
101+
throw utils.compilerError('Async compiler has already been disposed');
102102
}
103103
}
104104

@@ -163,7 +163,7 @@ export class AsyncCompiler {
163163
if (flag !== initFlag) {
164164
throw utils.compilerError(
165165
'AsyncCompiler can not be directly constructed. ' +
166-
'Please use `sass.initAsyncCompiler()` instead.',
166+
'Please use `sass.initAsyncCompiler()` instead',
167167
);
168168
}
169169
this.stderr$.subscribe(data => process.stderr.write(data));

lib/src/compiler/sync.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class Compiler {
154154

155155
for (;;) {
156156
if (!this.yield()) {
157-
throw utils.compilerError('Embedded compiler exited unexpectedly.');
157+
throw utils.compilerError('Embedded compiler exited unexpectedly');
158158
}
159159

160160
if (error) throw error;
@@ -168,7 +168,7 @@ export class Compiler {
168168
/** Guards against using a disposed compiler. */
169169
private throwIfDisposed(): void {
170170
if (this.disposed) {
171-
throw utils.compilerError('Sync compiler has already been disposed.');
171+
throw utils.compilerError('Sync compiler has already been disposed');
172172
}
173173
}
174174

@@ -177,7 +177,7 @@ export class Compiler {
177177
if (flag !== initFlag) {
178178
throw utils.compilerError(
179179
'Compiler can not be directly constructed. ' +
180-
'Please use `sass.initAsyncCompiler()` instead.',
180+
'Please use `sass.initCompiler()` instead',
181181
);
182182
}
183183
this.stderr$.subscribe(data => process.stderr.write(data));

lib/src/compiler/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export function handleCompileResponse(
225225
} else if (response.result.case === 'failure') {
226226
throw new Exception(response.result.value);
227227
} else {
228-
throw utils.compilerError('Compiler sent empty CompileResponse.');
228+
throw utils.compilerError('Compiler sent empty CompileResponse');
229229
}
230230
}
231231

lib/src/deprotofy-span.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ export function deprotofySourceSpan(buffer: proto.SourceSpan): SourceSpan {
1414
const text = buffer.text;
1515

1616
if (buffer.start === undefined) {
17-
throw compilerError('Expected SourceSpan to have start.');
17+
throw compilerError('Expected SourceSpan to have start');
1818
}
1919

2020
let end;
2121
if (buffer.end === undefined) {
2222
if (text !== '') {
23-
throw compilerError('Expected SourceSpan text to be empty.');
23+
throw compilerError('Expected SourceSpan text to be empty');
2424
} else {
2525
end = buffer.start;
2626
}
2727
} else {
2828
end = buffer.end;
2929
if (end.offset < buffer.start.offset) {
30-
throw compilerError('Expected SourceSpan end to be after start.');
30+
throw compilerError('Expected SourceSpan end to be after start');
3131
}
3232
}
3333

lib/src/protofier.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class Protofier {
324324
});
325325

326326
default:
327-
throw utils.compilerError(`Unknown color space "${color.space}".`);
327+
throw utils.compilerError(`Unknown color space "${color.space}"`);
328328
}
329329
}
330330

@@ -394,7 +394,7 @@ export class Protofier {
394394

395395
case 'hostFunction':
396396
throw utils.compilerError(
397-
'The compiler may not send Value.host_function.',
397+
'The compiler may not send Value.host_function',
398398
);
399399

400400
case 'compilerMixin':
@@ -454,7 +454,7 @@ export class Protofier {
454454
case 'calc':
455455
if (calculation.arguments.length !== 1) {
456456
throw utils.compilerError(
457-
'Value.Calculation.arguments must have exactly one argument for calc().',
457+
'Value.Calculation.arguments must have exactly one argument for calc()',
458458
);
459459
}
460460
return SassCalculation.calc(
@@ -466,7 +466,7 @@ export class Protofier {
466466
calculation.arguments.length > 3
467467
) {
468468
throw utils.compilerError(
469-
'Value.Calculation.arguments must have 1 to 3 arguments for clamp().',
469+
'Value.Calculation.arguments must have 1 to 3 arguments for clamp()',
470470
);
471471
}
472472
return SassCalculation.clamp(
@@ -481,7 +481,7 @@ export class Protofier {
481481
case 'min':
482482
if (calculation.arguments.length === 0) {
483483
throw utils.compilerError(
484-
'Value.Calculation.arguments must have at least 1 argument for min().',
484+
'Value.Calculation.arguments must have at least 1 argument for min()',
485485
);
486486
}
487487
return SassCalculation.min(
@@ -490,15 +490,15 @@ export class Protofier {
490490
case 'max':
491491
if (calculation.arguments.length === 0) {
492492
throw utils.compilerError(
493-
'Value.Calculation.arguments must have at least 1 argument for max().',
493+
'Value.Calculation.arguments must have at least 1 argument for max()',
494494
);
495495
}
496496
return SassCalculation.max(
497497
calculation.arguments.map(this.deprotofyCalculationValue),
498498
);
499499
default:
500500
throw utils.compilerError(
501-
`Value.Calculation.name "${calculation.name}" is not a recognized calculation type.`,
501+
`Value.Calculation.name "${calculation.name}" is not a recognized calculation type`,
502502
);
503503
}
504504
}

lib/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function compilerError(message: string): Error {
7373
* been included but was not.
7474
*/
7575
export function mandatoryError(field: string): Error {
76-
return compilerError(`Missing mandatory field ${field}`);
76+
return compilerError(`Missing mandatory field ${field}.`);
7777
}
7878

7979
/** Constructs a host-caused Error. */

lib/src/value/color.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function validateChannelInSpace(
249249
}
250250
if (!valid) {
251251
throw valueError(
252-
`Unknown channel name "${channel}" for color space "${space}".`,
252+
`Unknown channel name "${channel}" for color space "${space}"`,
253253
);
254254
}
255255
}
@@ -893,7 +893,7 @@ export class SassColor extends Value {
893893

894894
if (weight < 0 || weight > 1) {
895895
throw valueError(
896-
`Expected \`weight\` between \`0\` and \`1\`, received \`${weight}\`.`,
896+
`Expected \`weight\` between \`0\` and \`1\`, received \`${weight}\``,
897897
);
898898
}
899899

lib/src/value/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export abstract class Value implements ValueObject {
8686
}
8787
if (Math.abs(index) > this.lengthAsList) {
8888
throw valueError(
89-
`Invalid index ${sassIndex} for a list with ${this.lengthAsList} elements.`,
89+
`Invalid index ${sassIndex} for a list with ${this.lengthAsList} elements`,
9090
name,
9191
);
9292
}

lib/src/value/number.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ export class SassNumber extends Value {
596596
}
597597

598598
if (!otherHasUnits) {
599-
return valueError(`Expected ${this} to have no units.`, params.name);
599+
return valueError(`Expected ${this} to have no units`, params.name);
600600
}
601601

602602
// For single numerators, throw a detailed error with info about which unit
@@ -607,7 +607,7 @@ export class SassNumber extends Value {
607607
return valueError(
608608
`Expected ${this} to have a single ${type} unit (${unitsByType[
609609
type
610-
].join(', ')}).`,
610+
].join(', ')})`,
611611
params.name,
612612
);
613613
}
@@ -622,7 +622,7 @@ export class SassNumber extends Value {
622622
newNumerators,
623623
newDenominators,
624624
)}`
625-
}.`,
625+
}`,
626626
params.name,
627627
);
628628
};

0 commit comments

Comments
 (0)