All files / src/error spel-evaluation-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 198x 198x 198x   198x 198x 198x 198x 198x 198x 198x 198x         198x 2x 2x 2x   2x 198x  
import type { SpelMessage } from './spel-message.js';
 
/**
 * Parallels Spring SpelEvaluationException
 *
 * Exception during evaluation. Contains position and error code.
 */
export class SpelEvaluationException extends Error {
  public position: number;
  public readonly messageCode: SpelMessage;
  public readonly inserts: string[];
 
  constructor(position: number, messageCode: SpelMessage, ...inserts: string[]) {
    const msg = `SpelEvaluationException[${messageCode}]: ${inserts.join(', ')}`;
    super(msg);
    this.name = 'SpelEvaluationException';
    this.position = position;
    this.messageCode = messageCode;
    this.inserts = inserts;
  }
 
  /**
   * Full error message with expression string
   */
  public toDetailedString(expressionString: string): string {
    return (
      `SpelEvaluationException at position ${this.position.toString()} in "${expressionString}": ` +
      `[${this.messageCode.toString()}] ${this.inserts.join(', ')}`
    );
  }
}