| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.YAMLWarning = exports.YAMLSyntaxError = exports.YAMLSemanticError = exports.YAMLReferenceError = exports.YAMLError = void 0;
-
- var _Node = _interopRequireDefault(require("./cst/Node"));
-
- var _sourceUtils = require("./cst/source-utils");
-
- var _Range = _interopRequireDefault(require("./cst/Range"));
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- class YAMLError extends Error {
- constructor(name, source, message) {
- if (!message || !(source instanceof _Node.default)) throw new Error(`Invalid arguments for new ${name}`);
- super();
- this.name = name;
- this.message = message;
- this.source = source;
- }
-
- makePretty() {
- if (!this.source) return;
- this.nodeType = this.source.type;
- const cst = this.source.context && this.source.context.root;
-
- if (typeof this.offset === 'number') {
- this.range = new _Range.default(this.offset, this.offset + 1);
- const start = cst && (0, _sourceUtils.getLinePos)(this.offset, cst);
-
- if (start) {
- const end = {
- line: start.line,
- col: start.col + 1
- };
- this.linePos = {
- start,
- end
- };
- }
-
- delete this.offset;
- } else {
- this.range = this.source.range;
- this.linePos = this.source.rangeAsLinePos;
- }
-
- if (this.linePos) {
- const {
- line,
- col
- } = this.linePos.start;
- this.message += ` at line ${line}, column ${col}`;
- const ctx = cst && (0, _sourceUtils.getPrettyContext)(this.linePos, cst);
- if (ctx) this.message += `:\n\n${ctx}\n`;
- }
-
- delete this.source;
- }
-
- }
-
- exports.YAMLError = YAMLError;
-
- class YAMLReferenceError extends YAMLError {
- constructor(source, message) {
- super('YAMLReferenceError', source, message);
- }
-
- }
-
- exports.YAMLReferenceError = YAMLReferenceError;
-
- class YAMLSemanticError extends YAMLError {
- constructor(source, message) {
- super('YAMLSemanticError', source, message);
- }
-
- }
-
- exports.YAMLSemanticError = YAMLSemanticError;
-
- class YAMLSyntaxError extends YAMLError {
- constructor(source, message) {
- super('YAMLSyntaxError', source, message);
- }
-
- }
-
- exports.YAMLSyntaxError = YAMLSyntaxError;
-
- class YAMLWarning extends YAMLError {
- constructor(source, message) {
- super('YAMLWarning', source, message);
- }
-
- }
-
- exports.YAMLWarning = YAMLWarning;
|