refactor(yaml): change error message in stringifyNode() (#5839)

This commit is contained in:
Tim Reichen 2024-08-27 10:40:03 +02:00 committed by GitHub
parent eeaada9c18
commit 3dbccc5a84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View File

@ -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 !== "?") {

View File

@ -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({