UNPKG

read-gedcom

Version:
169 lines 5.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorDuplicatePointer = exports.ErrorIndexing = exports.ErrorEmptyTree = exports.ErrorTreeStructure = exports.ErrorInvalidRecordDefinition = exports.ErrorInvalidConcatenation = exports.ErrorInvalidNesting = exports.ErrorTreeSyntax = exports.ErrorTokenization = exports.ErrorUnsupportedCharset = exports.ErrorGedcomDecoding = exports.ErrorInvalidFileType = exports.ErrorParse = exports.ErrorGedcomBase = void 0; // See https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work const patchPrototype = (instance, target) => { const proto = target.prototype; if (Object.setPrototypeOf) { Object.setPrototypeOf(instance, proto); } else { this.__proto__ = proto; // eslint-disable-line no-proto } }; /** * The base type for all Gedcom related errors. All errors are currently also instances of {@link ErrorParse}. */ class ErrorGedcomBase extends Error { constructor(message) { super(message); patchPrototype(this, new.target); } } exports.ErrorGedcomBase = ErrorGedcomBase; /** * The base class of all parsing errors. */ class ErrorParse extends ErrorGedcomBase { constructor(message) { super(message); this.message = message; patchPrototype(this, new.target); } } exports.ErrorParse = ErrorParse; /** * Thrown if it is unlikely a Gedcom file, for instance if a completely unrelated file was passed. */ class ErrorInvalidFileType extends ErrorParse { } exports.ErrorInvalidFileType = ErrorInvalidFileType; /** * Thrown on likely Gedcom files if there was an error during the decoding of the characters. * Such an error can be muted by passing <code>false</code> to the <code>strict</code> parameter of a decoding method (for example, {@link decodeAnsel}). */ class ErrorGedcomDecoding extends ErrorParse { constructor(message, illegalCode) { super(message); this.illegalCode = illegalCode; patchPrototype(this, new.target); } } exports.ErrorGedcomDecoding = ErrorGedcomDecoding; /** * Thrown on likely Gedcom file in rare occasions if the charset was detected but is not supported. * An example would be UTF-32. */ class ErrorUnsupportedCharset extends ErrorParse { constructor(message, charset) { super(message); this.charset = charset; patchPrototype(this, new.target); } } exports.ErrorUnsupportedCharset = ErrorUnsupportedCharset; /** * Thrown on likely Gedcom files if a line could not be tokenized properly. * This is perhaps the most common error in practice. */ class ErrorTokenization extends ErrorParse { constructor(message, lineNumber, line) { super(message); this.lineNumber = lineNumber; this.line = line; patchPrototype(this, new.target); } } exports.ErrorTokenization = ErrorTokenization; /** * The base class of all tree structuring errors. * Such errors can be thrown only after the tokenization phase has completed successfully. */ class ErrorTreeSyntax extends ErrorParse { constructor(message, lineNumber) { super(message); this.lineNumber = lineNumber; patchPrototype(this, new.target); } } exports.ErrorTreeSyntax = ErrorTreeSyntax; /** * Thrown if a line is incorrectly nested. */ class ErrorInvalidNesting extends ErrorTreeSyntax { constructor(message, lineNumber, currentLevel, level) { super(message, lineNumber); this.lineNumber = lineNumber; this.currentLevel = currentLevel; this.level = level; patchPrototype(this, new.target); } } exports.ErrorInvalidNesting = ErrorInvalidNesting; /** * Thrown if a concatenation or a continuation line is incorrectly used. */ class ErrorInvalidConcatenation extends ErrorTreeSyntax { constructor(message, lineNumber, kind) { super(message, lineNumber); this.lineNumber = lineNumber; this.kind = kind; patchPrototype(this, new.target); } } exports.ErrorInvalidConcatenation = ErrorInvalidConcatenation; /** * Thrown if a record appears at a position other than the top-most level. */ class ErrorInvalidRecordDefinition extends ErrorTreeSyntax { constructor(message, lineNumber) { super(message, lineNumber); patchPrototype(this, new.target); } } exports.ErrorInvalidRecordDefinition = ErrorInvalidRecordDefinition; /** * Thrown if the file does not start with a header or does not end with a trailer. */ class ErrorTreeStructure extends ErrorParse { constructor(message) { super(message); patchPrototype(this, new.target); } } exports.ErrorTreeStructure = ErrorTreeStructure; /** * @deprecated This error cannot occur, an empty tree would throw a {@link ErrorInvalidFileType} instead. */ class ErrorEmptyTree extends ErrorTreeStructure { constructor(message) { super(message); patchPrototype(this, new.target); } } exports.ErrorEmptyTree = ErrorEmptyTree; /** * The base class of all indexing errors. * Such errors can occur if an inconsistency is discovered while indexing the data. */ class ErrorIndexing extends ErrorParse { constructor(message) { super(message); patchPrototype(this, new.target); } } exports.ErrorIndexing = ErrorIndexing; /** * Thrown if a duplicate pointer is discovered. */ class ErrorDuplicatePointer extends ErrorIndexing { constructor(message, lineNumber, lineNumberOriginalDefinition, pointer) { super(message); this.lineNumber = lineNumber; this.lineNumberOriginalDefinition = lineNumberOriginalDefinition; this.pointer = pointer; patchPrototype(this, new.target); } } exports.ErrorDuplicatePointer = ErrorDuplicatePointer; //# sourceMappingURL=error.js.map