All files / src/error spel-parse-exception.ts

100% Statements 18/18
100% Branches 3/3
100% Functions 3/3
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32              1x 45x 45x 45x   45x 45x 45x 45x 45x 45x 45x 45x         45x 2x 2x 2x   2x 45x  
import type { SpelMessage } from './spel-message.js';
 
/**
 * Parallels Spring SpelParseException
 *
 * Exception during parsing. Contains position and error code for diagnosis.
 */
export class SpelParseException extends Error {
  public readonly position: number;
  public readonly messageCode: SpelMessage;
  public readonly inserts: string[];
 
  constructor(position: number, messageCode: SpelMessage, ...inserts: string[]) {
    const msg = `SpelParseException[${messageCode}]: ${inserts.join(', ')}`;
    super(msg);
    this.name = 'SpelParseException';
    this.position = position;
    this.messageCode = messageCode;
    this.inserts = inserts;
  }
 
  /**
   * Full error message with expression string
   */
  public toDetailedString(expressionString: string): string {
    return (
      `SpelParseException at position ${this.position.toString()} in "${expressionString}": ` +
      `[${this.messageCode.toString()}] ${this.inserts.join(', ')}`
    );
  }
}