{"version":3,"sources":["../../../src/parser/nodes/error.ts"],"sourcesContent":["import Definitions from \"../../core/definitions\";\r\nimport { Position } from '../../core/positions';\r\nimport IOError from \"../../errors/io-error\";\r\nimport Node from \"./nodes\";\r\n\r\n/**\r\n * Error categories for styling and filtering\r\n */\r\nexport type ErrorCategory = 'syntax' | 'validation' | 'runtime';\r\n\r\n/**\r\n * ErrorNode represents a parsing error that occurred during AST construction.\r\n * This allows the parser to continue processing and collect multiple errors\r\n * instead of stopping at the first error encountered.\r\n *\r\n * @remarks\r\n * The error property accepts both IOError (preferred) and plain Error types\r\n * for backward compatibility. When IOError is used, additional properties\r\n * like errorCode, positionRange, and fact are available.\r\n */\r\nclass ErrorNode implements Node {\r\n  /**\r\n   * The error that caused this node to be created.\r\n   * Prefer IOError for full type-safe access to error properties.\r\n   */\r\n  readonly error: Error | IOError;\r\n  readonly position: Position;\r\n  readonly endPosition?: Position;\r\n\r\n  constructor(error: Error | IOError, position: Position, endPosition?: Position) {\r\n    this.error = error;\r\n    this.position = position;\r\n    this.endPosition = endPosition;\r\n  }\r\n\r\n  /**\r\n   * Type guard to check if the error is an IOError.\r\n   * Use this to safely access IOError-specific properties.\r\n   *\r\n   * @example\r\n   * ```ts\r\n   * if (errorNode.isIOError()) {\r\n   *   console.log(errorNode.error.errorCode);\r\n   * }\r\n   * ```\r\n   */\r\n  isIOError(): this is ErrorNode & { error: IOError } {\r\n    return this.error instanceof IOError;\r\n  }\r\n\r\n  /**\r\n   * Gets the error code if available.\r\n   * Returns undefined for plain Error instances.\r\n   */\r\n  get errorCode(): string | undefined {\r\n    return this.isIOError() ? this.error.errorCode : undefined;\r\n  }\r\n\r\n  /**\r\n   * Determines the error category based on the error type.\r\n   * This enables UI to apply different styling (e.g., red for syntax, orange for validation).\r\n   *\r\n   * @returns 'syntax' for parser/syntax errors, 'validation' for schema validation errors, 'runtime' for others\r\n   */\r\n  private getErrorCategory(): ErrorCategory {\r\n    const errorName = this.error.name;\r\n\r\n    // Check for InternetObject error types\r\n    if (errorName.includes('SyntaxError')) {\r\n      return 'syntax';\r\n    }\r\n    if (errorName.includes('ValidationError')) {\r\n      return 'validation';\r\n    }\r\n\r\n    // Fallback to runtime for unknown error types\r\n    return 'runtime';\r\n  }\r\n\r\n  /**\r\n   * Returns error information as a value object.\r\n   * This allows ErrorNodes to be serialized alongside valid nodes.\r\n   * Includes error category for UI styling and errorCode when available.\r\n   */\r\n  toValue(defs?: Definitions): any {\r\n    const base: any = {\r\n      __error: true,\r\n      category: this.getErrorCategory(),\r\n      message: this.error.message,\r\n      name: this.error.name,\r\n      position: this.position,\r\n      ...(this.endPosition && { endPosition: this.endPosition }),\r\n      ...(this.errorCode && { errorCode: this.errorCode })\r\n    };\r\n    // Include collectionIndex if the original error carries it (boundary context)\r\n    const anyErr: any = this.error as any;\r\n    if (anyErr && anyErr.collectionIndex !== undefined) {\r\n      base.collectionIndex = anyErr.collectionIndex;\r\n    }\r\n    return base;\r\n  }\r\n\r\n  /**\r\n   * Returns the starting position of the error.\r\n   */\r\n  getStartPos(): Position {\r\n    return this.position;\r\n  }\r\n\r\n  /**\r\n   * Returns the ending position of the error.\r\n   * If no end position was provided, returns the start position.\r\n   */\r\n  getEndPos(): Position {\r\n    return this.endPosition || this.position;\r\n  }\r\n}\r\n\r\nexport default ErrorNode;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAoB;AAkBpB,MAAM,UAA0B;AAAA;AAAA;AAAA;AAAA;AAAA,EAKrB;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,OAAwB,UAAoB,aAAwB;AAC9E,SAAK,QAAQ;AACb,SAAK,WAAW;AAChB,SAAK,cAAc;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,YAAoD;AAClD,WAAO,KAAK,iBAAiB,gBAAAA;AAAA,EAC/B;AAAA;AAAA;AA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