mirror of
https://github.com/denoland/std.git
synced 2024-11-21 12:40:03 +00:00
refactor(yaml): change error message in stringifyNode()
(#5839)
This commit is contained in:
parent
eeaada9c18
commit
3dbccc5a84
@ -29,7 +29,7 @@ import {
|
||||
} from "./_chars.ts";
|
||||
import { DEFAULT_SCHEMA, type Schema } from "./_schema.ts";
|
||||
import type { KindType, RepresentFn, StyleVariant, Type } from "./_type.ts";
|
||||
import { getObjectTypeString, isObject } from "./_utils.ts";
|
||||
import { isObject } from "./_utils.ts";
|
||||
|
||||
const STYLE_PLAIN = 1;
|
||||
const STYLE_SINGLE = 2;
|
||||
@ -838,9 +838,7 @@ export class DumperState {
|
||||
}
|
||||
} else {
|
||||
if (this.skipInvalid) return null;
|
||||
throw new TypeError(
|
||||
`Cannot stringify object of type: ${getObjectTypeString(value)}`,
|
||||
);
|
||||
throw new TypeError(`Cannot stringify ${typeof value}`);
|
||||
}
|
||||
|
||||
if (tag !== null && tag !== "?") {
|
||||
|
@ -140,11 +140,15 @@ Deno.test({
|
||||
Deno.test({
|
||||
name: "stringify() throws with `!!js/*` yaml types with default schemas",
|
||||
fn() {
|
||||
const object = { undefined: undefined };
|
||||
assertThrows(
|
||||
() => stringify(object),
|
||||
() => stringify(undefined),
|
||||
TypeError,
|
||||
"Cannot stringify object of type: [object Undefined]",
|
||||
"Cannot stringify undefined",
|
||||
);
|
||||
assertThrows(
|
||||
() => stringify(() => {}),
|
||||
TypeError,
|
||||
"Cannot stringify function",
|
||||
);
|
||||
},
|
||||
});
|
||||
@ -676,7 +680,10 @@ Deno.test("stringify() uses quotes around deprecated boolean notations when `com
|
||||
});
|
||||
|
||||
Deno.test("stringify() handles undefined with skipInvalid option", () => {
|
||||
assertEquals(stringify(undefined, { skipInvalid: true }), "");
|
||||
assertEquals(
|
||||
stringify(undefined, { skipInvalid: true }),
|
||||
"",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
|
Loading…
Reference in New Issue
Block a user