Skip to content

Commit

Permalink
BREAKING(yaml): replace YamlError with TypeError in stringify() (
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Jul 16, 2024
1 parent 07af28c commit dff594b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
9 changes: 4 additions & 5 deletions yaml/_dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
SINGLE_QUOTE,
VERTICAL_LINE,
} from "./_chars.ts";
import { YamlError } from "./_error.ts";
import { DEFAULT_SCHEMA, type Schema } from "./_schema.ts";
import type { StyleVariant, Type } from "./_type.ts";
import { type ArrayObject, getObjectTypeString, isObject } from "./_utils.ts";
Expand Down Expand Up @@ -577,7 +576,7 @@ export class DumperState {
case STYLE_DOUBLE:
return `"${escapeString(string)}"`;
default:
throw new YamlError("impossible error: invalid scalar style");
throw new TypeError("impossible error: invalid scalar style");
}
};
this.dump = createDump();
Expand Down Expand Up @@ -701,7 +700,7 @@ export class DumperState {
objectKeyList.sort(this.sortKeys);
} else if (this.sortKeys) {
// Something is wrong
throw new YamlError("sortKeys must be a boolean or a function");
throw new TypeError("sortKeys must be a boolean or a function");
}

for (const [index, objectKey] of objectKeyList.entries()) {
Expand Down Expand Up @@ -789,7 +788,7 @@ export class DumperState {
this.dump = type.represent[style]!(object, style);
return true;
}
throw new YamlError(
throw new TypeError(
`!<${type.tag}> tag resolver accepts not "${style}" style`,
);
}
Expand Down Expand Up @@ -879,7 +878,7 @@ export class DumperState {
}
} else {
if (this.skipInvalid) return false;
throw new YamlError(
throw new TypeError(
`unacceptable kind of an object to dump ${
getObjectTypeString(this.dump)
}`,
Expand Down
13 changes: 0 additions & 13 deletions yaml/_error.ts

This file was deleted.

1 change: 1 addition & 0 deletions yaml/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export type StringifyOptions = {
* assertEquals(yaml, "id: 1\nname: Alice\n");
* ```
*
* @throws {TypeError} If `data` contains invalid types.
* @param data The data to serialize.
* @param options The options for serialization.
* @returns A YAML string.
Expand Down
3 changes: 1 addition & 2 deletions yaml/stringify_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import { assertEquals, assertThrows } from "@std/assert";
import { stringify } from "./stringify.ts";
import { YamlError } from "./_error.ts";

Deno.test({
name: "stringify()",
Expand Down Expand Up @@ -143,7 +142,7 @@ Deno.test({
const object = { undefined: undefined };
assertThrows(
() => stringify(object),
YamlError,
TypeError,
"unacceptable kind of an object to dump",
);
},
Expand Down

0 comments on commit dff594b

Please sign in to comment.