{"version":3,"sources":["../../src/errors/io-error.ts"],"sourcesContent":["import PositionRange from \"../core/positions\"\r\n\r\n/**\r\n * Represents the base error class in InternetObject.\r\n */\r\nclass IOError extends Error {\r\n  // Due to a bug in TypeScript specifically control the __proto__\r\n  // Ref: https://github.com/Microsoft/TypeScript/issues/13965\r\n  // If not, `instanceof` and `catch` won't work properly\r\n  // tslint:disable-next-line:variable-name\r\n  public __proto__: Error\r\n\r\n  /**\r\n   * An error-code associated with the current error.\r\n   */\r\n  public errorCode: string\r\n\r\n  /**\r\n   * A fact object, which may contain additional information about the error.\r\n   */\r\n  public fact?: string\r\n\r\n  /**\r\n   * A position object, for tracking line and columns.\r\n   */\r\n  #positionRange?: PositionRange\r\n  get positionRange() { return this.#positionRange }\r\n  set positionRange(value: PositionRange | undefined) {\r\n    this.#positionRange = value\r\n    this.updateMessage()\r\n  }\r\n\r\n  /**\r\n   * Backward-compat: some tests and callers expect `code` instead of `errorCode`.\r\n   */\r\n  get code(): string { return this.errorCode }\r\n\r\n  /**\r\n   * Backward-compat: expose `position` alias for `positionRange` used by older tests.\r\n   */\r\n  get position(): any { return this.#positionRange as any }\r\n\r\n  /**\r\n   * Indicates whether the error is caused by EOF.\r\n   */\r\n  public isEof: boolean\r\n\r\n  /**\r\n   * Initialize the new instance of `IOError`.\r\n   *\r\n   * @param errorCode {string} An error-code associated with this error\r\n   * @param fact {string} The  reason for the error\r\n   * @param pos {Position} The position object, for tracking line and columns. Optional\r\n   * @param isEof {boolean} Indicates whether the error is caused by EOF. Optional\r\n   * @param ssf {Function} The start statck function, removes the irrelavant frames from the stack trace\r\n   */\r\n  constructor(errorCode: string, fact?: string, positionRange?: PositionRange, isEof: boolean = false, ssf?: any) {\r\n    super()\r\n\r\n    this.errorCode      = errorCode\r\n    this.fact           = fact\r\n    this.#positionRange = positionRange\r\n    this.isEof          = isEof\r\n    this.name           = 'IOError'\r\n\r\n    // Format the error message\r\n    this.updateMessage()\r\n\r\n    // TODO: After stability, change the SSF class\r\n    // Error.captureStackTrace(this, IOError)\r\n    // Error.captureStackTrace(this, ssf || InternetObject)\r\n    this.__proto__ = new.target.prototype\r\n  }\r\n\r\n\r\n  protected updateMessage() {\r\n    let errorMsg = `\"${this.errorCode}\" `\r\n    if (this.fact) {\r\n      errorMsg += `\"${this.fact}\" `\r\n    }\r\n\r\n    if (this.isEof) {\r\n      errorMsg += `at EOF`\r\n    } else if (this.#positionRange) {\r\n      // Handle both PositionRange (with getStartPos) and plain Position-like objects\r\n      const pr: any = this.#positionRange as any\r\n      if (typeof pr.getStartPos === 'function') {\r\n        const startPos = pr.getStartPos()\r\n        errorMsg += `at ${startPos.row}:${startPos.col}`\r\n      } else if (typeof pr.row === 'number' && typeof pr.col === 'number') {\r\n        errorMsg += `at ${pr.row}:${pr.col}`\r\n      }\r\n    }\r\n\r\n    this.message = errorMsg\r\n  }\r\n}\r\n\r\nexport default IOError\r\n\r\n\r\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,MAAM,gBAAgB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAKnB;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKP;AAAA,EACA,IAAI,gBAAgB;AAAE,WAAO,KAAK;AAAA,EAAe;AAAA,EACjD,IAAI,cAAc,OAAkC;AAClD,SAAK,iBAAiB;AACtB,SAAK,cAAc;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAe;AAAE,WAAO,KAAK;AAAA,EAAU;AAAA;AAAA;AAAA;AAAA,EAK3C,IAAI,WAAgB;AAAE,WAAO,KAAK;AAAA,EAAsB;AAAA;AAAA;AAAA;AAAA,EAKjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWP,YAAY,WAAmB,MAAe,eAA+B,QAAiB,OAAO,KAAW;AAC9G,UAAM;AAEN,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