Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(yaml): rename YAMLError to YamlError #5149

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
handle = "U";
length = 8;
} else {
throw new YAMLError(
throw new YamlError(

Check warning on line 92 in yaml/_dumper/dumper.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_dumper/dumper.ts#L92

Added line #L92 was not covered by tests
"code point within a string may not be greater than 0xFFFFFFFF",
);
}
Expand Down Expand Up @@ -497,7 +497,7 @@
case STYLE_DOUBLE:
return `"${escapeString(string)}"`;
default:
throw new YAMLError("impossible error: invalid scalar style");
throw new YamlError("impossible error: invalid scalar style");

Check warning on line 500 in yaml/_dumper/dumper.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_dumper/dumper.ts#L500

Added line #L500 was not covered by tests
}
})();
}
Expand Down Expand Up @@ -611,7 +611,7 @@
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");

Check warning on line 614 in yaml/_dumper/dumper.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_dumper/dumper.ts#L614

Added line #L614 was not covered by tests
}

for (const [index, objectKey] of objectKeyList.entries()) {
Expand Down Expand Up @@ -693,7 +693,7 @@
style,
);
} else {
throw new YAMLError(
throw new YamlError(

Check warning on line 696 in yaml/_dumper/dumper.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_dumper/dumper.ts#L696

Added line #L696 was not covered by tests
`!<${type.tag}> tag resolver accepts not "${style}" style`,
);
}
Expand Down Expand Up @@ -786,7 +786,7 @@
}
} 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 @@
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 @@
if (documents.length === 1) {
return documents[0];
}
throw new YAMLError(
throw new YamlError(

Check warning on line 1800 in yaml/_loader/loader.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_loader/loader.ts#L1800

Added line #L1800 was not covered by tests
"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 @@

for (const type of this.implicit) {
if (type.loadKind && type.loadKind !== "scalar") {
throw new YAMLError(
throw new YamlError(

Check warning on line 75 in yaml/schema.ts

View check run for this annotation

Codecov / codecov/patch

yaml/schema.ts#L75

Added line #L75 was not covered by tests
"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