1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

refactor(cli/js): align error messages (#25406)

Aligns the error messages in the cli/js folder to be in-line with the
Deno style guide.
This commit is contained in:
Ian Bull 2024-09-04 00:19:55 -07:00 committed by GitHub
parent 072bf5d379
commit 939c23f9fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 34 additions and 34 deletions

View file

@ -104,12 +104,12 @@ function bench(
} }
if (optionsOrFn.fn != undefined) { if (optionsOrFn.fn != undefined) {
throw new TypeError( throw new TypeError(
"Unexpected 'fn' field in options, bench function is already provided as the third argument.", "Unexpected 'fn' field in options, bench function is already provided as the third argument",
); );
} }
if (optionsOrFn.name != undefined) { if (optionsOrFn.name != undefined) {
throw new TypeError( throw new TypeError(
"Unexpected 'name' field in options, bench name is already provided as the first argument.", "Unexpected 'name' field in options, bench name is already provided as the first argument",
); );
} }
benchDesc = { benchDesc = {
@ -141,7 +141,7 @@ function bench(
fn = optionsOrFn; fn = optionsOrFn;
if (nameOrFnOrOptions.fn != undefined) { if (nameOrFnOrOptions.fn != undefined) {
throw new TypeError( throw new TypeError(
"Unexpected 'fn' field in options, bench function is already provided as the second argument.", "Unexpected 'fn' field in options, bench function is already provided as the second argument",
); );
} }
name = nameOrFnOrOptions.name ?? fn.name; name = nameOrFnOrOptions.name ?? fn.name;
@ -150,7 +150,7 @@ function bench(
!nameOrFnOrOptions.fn || typeof nameOrFnOrOptions.fn !== "function" !nameOrFnOrOptions.fn || typeof nameOrFnOrOptions.fn !== "function"
) { ) {
throw new TypeError( throw new TypeError(
"Expected 'fn' field in the first argument to be a bench function.", "Expected 'fn' field in the first argument to be a bench function",
); );
} }
fn = nameOrFnOrOptions.fn; fn = nameOrFnOrOptions.fn;
@ -385,12 +385,12 @@ function createBenchContext(desc) {
start() { start() {
if (currentBenchId !== desc.id) { if (currentBenchId !== desc.id) {
throw new TypeError( throw new TypeError(
"The benchmark which this context belongs to is not being executed.", "The benchmark which this context belongs to is not being executed",
); );
} }
if (currentBenchUserExplicitStart != null) { if (currentBenchUserExplicitStart != null) {
throw new TypeError( throw new TypeError(
"BenchContext::start() has already been invoked.", "BenchContext::start() has already been invoked",
); );
} }
currentBenchUserExplicitStart = benchNow(); currentBenchUserExplicitStart = benchNow();
@ -399,11 +399,11 @@ function createBenchContext(desc) {
const end = benchNow(); const end = benchNow();
if (currentBenchId !== desc.id) { if (currentBenchId !== desc.id) {
throw new TypeError( throw new TypeError(
"The benchmark which this context belongs to is not being executed.", "The benchmark which this context belongs to is not being executed",
); );
} }
if (currentBenchUserExplicitEnd != null) { if (currentBenchUserExplicitEnd != null) {
throw new TypeError("BenchContext::end() has already been invoked."); throw new TypeError("BenchContext::end() has already been invoked");
} }
currentBenchUserExplicitEnd = end; currentBenchUserExplicitEnd = end;
}, },

View file

@ -113,7 +113,7 @@ function assertExit(fn, isTest) {
throw new Error( throw new Error(
`${ `${
isTest ? "Test case" : "Bench" isTest ? "Test case" : "Bench"
} finished with exit code set to ${exitCode}.`, } finished with exit code set to ${exitCode}`,
); );
} }
if (innerResult) { if (innerResult) {
@ -242,12 +242,12 @@ function testInner(
} }
if (optionsOrFn.fn != undefined) { if (optionsOrFn.fn != undefined) {
throw new TypeError( throw new TypeError(
"Unexpected 'fn' field in options, test function is already provided as the third argument.", "Unexpected 'fn' field in options, test function is already provided as the third argument",
); );
} }
if (optionsOrFn.name != undefined) { if (optionsOrFn.name != undefined) {
throw new TypeError( throw new TypeError(
"Unexpected 'name' field in options, test name is already provided as the first argument.", "Unexpected 'name' field in options, test name is already provided as the first argument",
); );
} }
testDesc = { testDesc = {
@ -279,7 +279,7 @@ function testInner(
fn = optionsOrFn; fn = optionsOrFn;
if (nameOrFnOrOptions.fn != undefined) { if (nameOrFnOrOptions.fn != undefined) {
throw new TypeError( throw new TypeError(
"Unexpected 'fn' field in options, test function is already provided as the second argument.", "Unexpected 'fn' field in options, test function is already provided as the second argument",
); );
} }
name = nameOrFnOrOptions.name ?? fn.name; name = nameOrFnOrOptions.name ?? fn.name;
@ -288,7 +288,7 @@ function testInner(
!nameOrFnOrOptions.fn || typeof nameOrFnOrOptions.fn !== "function" !nameOrFnOrOptions.fn || typeof nameOrFnOrOptions.fn !== "function"
) { ) {
throw new TypeError( throw new TypeError(
"Expected 'fn' field in the first argument to be a test function.", "Expected 'fn' field in the first argument to be a test function",
); );
} }
fn = nameOrFnOrOptions.fn; fn = nameOrFnOrOptions.fn;
@ -426,7 +426,7 @@ function createTestContext(desc) {
let stepDesc; let stepDesc;
if (typeof nameOrFnOrOptions === "string") { if (typeof nameOrFnOrOptions === "string") {
if (typeof maybeFn !== "function") { if (typeof maybeFn !== "function") {
throw new TypeError("Expected function for second argument."); throw new TypeError("Expected function for second argument");
} }
stepDesc = { stepDesc = {
name: nameOrFnOrOptions, name: nameOrFnOrOptions,
@ -434,7 +434,7 @@ function createTestContext(desc) {
}; };
} else if (typeof nameOrFnOrOptions === "function") { } else if (typeof nameOrFnOrOptions === "function") {
if (!nameOrFnOrOptions.name) { if (!nameOrFnOrOptions.name) {
throw new TypeError("The step function must have a name."); throw new TypeError("The step function must have a name");
} }
if (maybeFn != undefined) { if (maybeFn != undefined) {
throw new TypeError( throw new TypeError(
@ -449,7 +449,7 @@ function createTestContext(desc) {
stepDesc = nameOrFnOrOptions; stepDesc = nameOrFnOrOptions;
} else { } else {
throw new TypeError( throw new TypeError(
"Expected a test definition or name and function.", "Expected a test definition or name and function",
); );
} }
stepDesc.ignore ??= false; stepDesc.ignore ??= false;

View file

@ -8,17 +8,17 @@ benchmark time/iter (avg) iter/s (min … max) p75
start and end [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD] start and end [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD]
start only [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD] start only [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD]
end only [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD] end only [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD]
double start error: TypeError: BenchContext::start() has already been invoked. double start error: TypeError: BenchContext::start() has already been invoked
t.start(); t.start();
^ ^
at BenchContext.start ([WILDCARD]) at BenchContext.start ([WILDCARD])
at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD] at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD]
double end error: TypeError: BenchContext::end() has already been invoked. double end error: TypeError: BenchContext::end() has already been invoked
t.end(); t.end();
^ ^
at BenchContext.end ([WILDCARD]) at BenchContext.end ([WILDCARD])
at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD] at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD]
captured error: TypeError: The benchmark which this context belongs to is not being executed. captured error: TypeError: The benchmark which this context belongs to is not being executed
captured!.start(); captured!.start();
^ ^
at BenchContext.start ([WILDCARD]) at BenchContext.start ([WILDCARD])

View file

@ -4,7 +4,7 @@ Deno.exitCode ... FAILED ([WILDCARD])
ERRORS ERRORS
Deno.exitCode => ./main.js:1:6 Deno.exitCode => ./main.js:1:6
error: Error: Test case finished with exit code set to 42. error: Error: Test case finished with exit code set to 42
at exitSanitizer (ext:cli/40_test.js:113:15) at exitSanitizer (ext:cli/40_test.js:113:15)
at async outerWrapped (ext:cli/40_test.js:134:14) at async outerWrapped (ext:cli/40_test.js:134:14)

View file

@ -11,7 +11,7 @@ error: Error
at [WILDCARD]/exit_code2/main.js:3:9 at [WILDCARD]/exit_code2/main.js:3:9
success => ./main.js:6:6 success => ./main.js:6:6
error: Error: Test case finished with exit code set to 5. error: Error: Test case finished with exit code set to 5
at exitSanitizer (ext:cli/40_test.js:113:15) at exitSanitizer (ext:cli/40_test.js:113:15)
at async outerWrapped (ext:cli/40_test.js:134:14) at async outerWrapped (ext:cli/40_test.js:134:14)

View file

@ -5,7 +5,7 @@ success ... ok ([WILDCARD])
ERRORS ERRORS
Deno.exitCode => ./main.js:1:6 Deno.exitCode => ./main.js:1:6
error: Error: Test case finished with exit code set to 42. error: Error: Test case finished with exit code set to 42
at exitSanitizer (ext:cli/40_test.js:113:15) at exitSanitizer (ext:cli/40_test.js:113:15)
at async outerWrapped (ext:cli/40_test.js:134:14) at async outerWrapped (ext:cli/40_test.js:134:14)

View file

@ -8,17 +8,17 @@ benchmark time/iter (avg) iter/s (min … max) p75
start and end [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD] start and end [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD]
start only [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD] start only [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD]
end only [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD] end only [WILDCARD] [WILDCARD] [WILDCARD] ([WILDCARD] … [WILDCARD]) [WILDCARD]
double start error: Type error: BenchContext::start() has already been invoked. double start error: Type error: BenchContext::start() has already been invoked
t.start(); t.start();
^ ^
at BenchContext.start ([WILDCARD]) at BenchContext.start ([WILDCARD])
at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD] at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD]
double end error: Type error: BenchContext::end() has already been invoked. double end error: Type error: BenchContext::end() has already been invoked
t.end(); t.end();
^ ^
at BenchContext.end ([WILDCARD]) at BenchContext.end ([WILDCARD])
at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD] at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD]
captured error: Type error: The benchmark which this context belongs to is not being executed. captured error: Type error: The benchmark which this context belongs to is not being executed
captured!.start(); captured!.start();
^ ^
at BenchContext.start ([WILDCARD]) at BenchContext.start ([WILDCARD])

View file

@ -8,7 +8,7 @@ Deno.test(function testWrongOverloads() {
Deno.test("some name", { fn: () => {} }, () => {}); Deno.test("some name", { fn: () => {} }, () => {});
}, },
TypeError, TypeError,
"Unexpected 'fn' field in options, test function is already provided as the third argument.", "Unexpected 'fn' field in options, test function is already provided as the third argument",
); );
assertThrows( assertThrows(
() => { () => {
@ -16,7 +16,7 @@ Deno.test(function testWrongOverloads() {
Deno.test("some name", { name: "some name2" }, () => {}); Deno.test("some name", { name: "some name2" }, () => {});
}, },
TypeError, TypeError,
"Unexpected 'name' field in options, test name is already provided as the first argument.", "Unexpected 'name' field in options, test name is already provided as the first argument",
); );
assertThrows( assertThrows(
() => { () => {
@ -40,7 +40,7 @@ Deno.test(function testWrongOverloads() {
Deno.test({ fn: () => {} }, function foo() {}); Deno.test({ fn: () => {} }, function foo() {});
}, },
TypeError, TypeError,
"Unexpected 'fn' field in options, test function is already provided as the second argument.", "Unexpected 'fn' field in options, test function is already provided as the second argument",
); );
assertThrows( assertThrows(
() => { () => {
@ -48,7 +48,7 @@ Deno.test(function testWrongOverloads() {
Deno.test({}); Deno.test({});
}, },
TypeError, TypeError,
"Expected 'fn' field in the first argument to be a test function.", "Expected 'fn' field in the first argument to be a test function",
); );
assertThrows( assertThrows(
() => { () => {
@ -56,7 +56,7 @@ Deno.test(function testWrongOverloads() {
Deno.test({ fn: "boo!" }); Deno.test({ fn: "boo!" });
}, },
TypeError, TypeError,
"Expected 'fn' field in the first argument to be a test function.", "Expected 'fn' field in the first argument to be a test function",
); );
}); });
@ -87,7 +87,7 @@ Deno.test(async function invalidStepArguments(t) {
await (t as any).step("test"); await (t as any).step("test");
}, },
TypeError, TypeError,
"Expected function for second argument.", "Expected function for second argument",
); );
await assertRejects( await assertRejects(
@ -96,7 +96,7 @@ Deno.test(async function invalidStepArguments(t) {
await (t as any).step("test", "not a function"); await (t as any).step("test", "not a function");
}, },
TypeError, TypeError,
"Expected function for second argument.", "Expected function for second argument",
); );
await assertRejects( await assertRejects(
@ -105,7 +105,7 @@ Deno.test(async function invalidStepArguments(t) {
await (t as any).step(); await (t as any).step();
}, },
TypeError, TypeError,
"Expected a test definition or name and function.", "Expected a test definition or name and function",
); );
await assertRejects( await assertRejects(
@ -114,7 +114,7 @@ Deno.test(async function invalidStepArguments(t) {
await (t as any).step(() => {}); await (t as any).step(() => {});
}, },
TypeError, TypeError,
"The step function must have a name.", "The step function must have a name",
); );
}); });