YamlSyntaxError
import { YamlSyntaxError } from "jsr:@ende/yaml";class
class YamlSyntaxError extends SyntaxErrorError thrown when YAML parsing fails.
Subclass of SyntaxError, so existing
instanceof SyntaxError checks keep working. Carries structured
position information so consumers do not have to parse the message.
Example: Usage
import { parse, YamlSyntaxError } from "@ende/yaml";
import { assertInstanceOf } from "@ende/assert";
try {
parse(`"`);
} catch (error) {
assertInstanceOf(error, YamlSyntaxError);
assertInstanceOf(error, SyntaxError);
}
Constructors
constructor
new YamlSyntaxError(message: string, position: YamlPosition, snippet?: string)Constructs a new YamlSyntaxError.
The constructed message is ${message} at line ${line}, column ${column},
with :\n${snippet} appended when a snippet is provided.
message: stringThe error message describing the syntax issue.
position: YamlPositionThe position in the YAML source where the error occurred.
snippet?: stringOptional formatted snippet of the source around the error.
Properties
line
readonly line: numberThe line number where the error occurred (1-indexed).
Example: Usage
import { YamlSyntaxError } from "@ende/yaml";
import { assertEquals } from "@ende/assert";
const error = new YamlSyntaxError("Test", { line: 5, column: 10, offset: 50 });
assertEquals(error.line, 5);
column
readonly column: numberThe column number where the error occurred (1-indexed).
Example: Usage
import { YamlSyntaxError } from "@ende/yaml";
import { assertEquals } from "@ende/assert";
const error = new YamlSyntaxError("Test", { line: 5, column: 10, offset: 50 });
assertEquals(error.column, 10);
offset
readonly offset: numberThe character offset where the error occurred (0-indexed).
Example: Usage
import { YamlSyntaxError } from "@ende/yaml";
import { assertEquals } from "@ende/assert";
const error = new YamlSyntaxError("Test", { line: 5, column: 10, offset: 50 });
assertEquals(error.offset, 50);
snippet
readonly snippet?: stringA formatted snippet of the source around the error, including a caret line indicating the column. Undefined when the source is empty.
Example: Usage
import { YamlSyntaxError } from "@ende/yaml";
import { assertEquals } from "@ende/assert";
const snippet = " foo: bar\n ^";
const error = new YamlSyntaxError(
"Test",
{ line: 1, column: 6, offset: 5 },
snippet,
);
assertEquals(error.snippet, snippet);