Skip to content

Commit

Permalink
refactor(yaml): rename YAMLError to YamlError (#5149)
Browse files Browse the repository at this point in the history
BREAKING(yaml): rename `YAMLError` to `YamlError`
  • Loading branch information
iuioiua authored Jun 27, 2024
1 parent 5811712 commit ef4231e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions yaml/_dumper/dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { YAMLError } from "../_error.ts";
import { YamlError } from "../_error.ts";
import type { RepresentFn } from "../type.ts";
import * as common from "../_utils.ts";
import { DumperState, type DumperStateOptions } from "./dumper_state.ts";
Expand Down Expand Up @@ -89,7 +89,7 @@ function encodeHex(character: number): string {
handle = "U";
length = 8;
} else {
throw new YAMLError(
throw new YamlError(
"code point within a string may not be greater than 0xFFFFFFFF",
);
}
Expand Down Expand Up @@ -497,7 +497,7 @@ function writeScalar(
case STYLE_DOUBLE:
return `"${escapeString(string)}"`;
default:
throw new YAMLError("impossible error: invalid scalar style");
throw new YamlError("impossible error: invalid scalar style");
}
})();
}
Expand Down Expand Up @@ -611,7 +611,7 @@ function writeBlockMapping(
objectKeyList.sort(state.sortKeys);
} else if (state.sortKeys) {
// Something is wrong
throw new YAMLError("sortKeys must be a boolean or a function");
throw new YamlError("sortKeys must be a boolean or a function");
}

for (const [index, objectKey] of objectKeyList.entries()) {
Expand Down Expand Up @@ -693,7 +693,7 @@ function detectType(
style,
);
} else {
throw new YAMLError(
throw new YamlError(
`!<${type.tag}> tag resolver accepts not "${style}" style`,
);
}
Expand Down Expand Up @@ -786,7 +786,7 @@ function writeNode(
}
} else {
if (state.skipInvalid) return false;
throw new YAMLError(`unacceptable kind of an object to dump ${type}`);
throw new YamlError(`unacceptable kind of an object to dump ${type}`);
}

if (state.tag !== null && state.tag !== "?") {
Expand Down
2 changes: 1 addition & 1 deletion yaml/_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import type { Mark } from "./_mark.ts";

export class YAMLError extends Error {
export class YamlError extends Error {
constructor(
message = "(unknown reason)",
protected mark: Mark | string = "",
Expand Down
8 changes: 4 additions & 4 deletions yaml/_loader/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { YAMLError } from "../_error.ts";
import { YamlError } from "../_error.ts";
import { Mark } from "../_mark.ts";
import type { Type } from "../type.ts";
import * as common from "../_utils.ts";
Expand Down Expand Up @@ -161,8 +161,8 @@ for (let i = 0; i < 256; i++) {
simpleEscapeMap[i] = simpleEscapeSequence(i);
}

function generateError(state: LoaderState, message: string): YAMLError {
return new YAMLError(
function generateError(state: LoaderState, message: string): YamlError {
return new YamlError(
message,
new Mark(
state.filename as string,
Expand Down Expand Up @@ -1797,7 +1797,7 @@ export function load(input: string, options?: LoaderStateOptions): unknown {
if (documents.length === 1) {
return documents[0];
}
throw new YAMLError(
throw new YamlError(
"expected a single document in the stream, but found more",
);
}
4 changes: 2 additions & 2 deletions yaml/_loader/loader_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import type { YAMLError } from "../_error.ts";
import type { YamlError } from "../_error.ts";
import type { Schema, SchemaDefinition, TypeMap } from "../schema.ts";
import { State } from "../_state.ts";
import type { Type } from "../type.ts";
Expand All @@ -19,7 +19,7 @@ export interface LoaderStateOptions {
/** compatibility with JSON.parse behaviour. */
json?: boolean;
/** function to call on warning messages. */
onWarning?(this: null, e?: YAMLError): void;
onWarning?(this: null, e?: YamlError): void;
}

// deno-lint-ignore no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion yaml/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface ParseOptions {
* assertEquals(data, { id: 1, name: "Alice" });
* ```
*
* @throws {YAMLError} Throws error on invalid YAML.
* @throws {YamlError} Throws error on invalid YAML.
* @param content YAML string to parse.
* @param options Parsing options.
* @returns Parsed document.
Expand Down
12 changes: 6 additions & 6 deletions yaml/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { parse, parseAll } from "./parse.ts";
import { assert, assertEquals, assertThrows } from "@std/assert";
import { DEFAULT_SCHEMA, EXTENDED_SCHEMA } from "./schema/mod.ts";
import { YAMLError } from "./_error.ts";
import { YamlError } from "./_error.ts";
import { Type } from "./type.ts";

Deno.test({
Expand Down Expand Up @@ -62,7 +62,7 @@ Deno.test({
name: "parse() throws with `!!js/*` yaml types with default schemas",
fn() {
const yaml = `undefined: !!js/undefined ~`;
assertThrows(() => parse(yaml), YAMLError, "unknown tag !");
assertThrows(() => parse(yaml), YamlError, "unknown tag !");
},
});

Expand Down Expand Up @@ -291,25 +291,25 @@ Deno.test({
// map entry is not an object
assertThrows(
() => parse("--- !!omap\n- 1"),
YAMLError,
YamlError,
"cannot resolve a node with !<tag:yaml.org,2002:omap> explicit tag",
);
// map entry is empty object
assertThrows(
() => parse("--- !!omap\n- {}"),
YAMLError,
YamlError,
"cannot resolve a node with !<tag:yaml.org,2002:omap> explicit tag",
);
// map entry is an object with multiple keys
assertThrows(
() => parse("--- !!omap\n- foo: 1\n bar: 2"),
YAMLError,
YamlError,
"cannot resolve a node with !<tag:yaml.org,2002:omap> explicit tag",
);
// 2 map entries have the same key
assertThrows(
() => parse("--- !!omap\n- foo: 1\n- foo: 2"),
YAMLError,
YamlError,
"cannot resolve a node with !<tag:yaml.org,2002:omap> explicit tag",
);
},
Expand Down
4 changes: 2 additions & 2 deletions yaml/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { YAMLError } from "./_error.ts";
import { YamlError } from "./_error.ts";
import type { KindType, Type } from "./type.ts";
import type { Any, ArrayObject } from "./_utils.ts";

Expand Down Expand Up @@ -72,7 +72,7 @@ export class Schema implements SchemaDefinition {

for (const type of this.implicit) {
if (type.loadKind && type.loadKind !== "scalar") {
throw new YAMLError(
throw new YamlError(
"There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.",
);
}
Expand Down
4 changes: 2 additions & 2 deletions yaml/stringify_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { assertEquals, assertThrows } from "@std/assert";
import { stringify } from "./stringify.ts";
import { YAMLError } from "./_error.ts";
import { YamlError } from "./_error.ts";
import { DEFAULT_SCHEMA, EXTENDED_SCHEMA } from "./schema/mod.ts";
import { Type } from "./type.ts";

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

0 comments on commit ef4231e

Please sign in to comment.