1
+ import { UnscopedValidationError } from '../../core' ;
2
+
1
3
// Implementation of metric patterns
2
4
3
5
/**
@@ -180,7 +182,7 @@ export class FilterPattern {
180
182
* A JSON log pattern that matches if all given JSON log patterns match
181
183
*/
182
184
public static all ( ...patterns : JsonPattern [ ] ) : JsonPattern {
183
- if ( patterns . length === 0 ) { throw new Error ( 'Must supply at least one pattern, or use allEvents() to match all events.' ) ; }
185
+ if ( patterns . length === 0 ) { throw new UnscopedValidationError ( 'Must supply at least one pattern, or use allEvents() to match all events.' ) ; }
184
186
if ( patterns . length === 1 ) { return patterns [ 0 ] ; }
185
187
return new JSONAggregatePattern ( '&&' , patterns ) ;
186
188
}
@@ -189,7 +191,7 @@ export class FilterPattern {
189
191
* A JSON log pattern that matches if any of the given JSON log patterns match
190
192
*/
191
193
public static any ( ...patterns : JsonPattern [ ] ) : JsonPattern {
192
- if ( patterns . length === 0 ) { throw new Error ( 'Must supply at least one pattern' ) ; }
194
+ if ( patterns . length === 0 ) { throw new UnscopedValidationError ( 'Must supply at least one pattern' ) ; }
193
195
if ( patterns . length === 1 ) { return patterns [ 0 ] ; }
194
196
return new JSONAggregatePattern ( '||' , patterns ) ;
195
197
}
@@ -282,7 +284,7 @@ class JSONPostfixPattern extends JsonPattern {
282
284
class JSONAggregatePattern extends JsonPattern {
283
285
public constructor ( operator : string , patterns : JsonPattern [ ] ) {
284
286
if ( operator !== '&&' && operator !== '||' ) {
285
- throw new Error ( 'Operator must be one of && or ||' ) ;
287
+ throw new UnscopedValidationError ( 'Operator must be one of && or ||' ) ;
286
288
}
287
289
288
290
const clauses = patterns . map ( p => '(' + p . jsonPatternString + ')' ) ;
@@ -313,12 +315,12 @@ export class SpaceDelimitedTextPattern implements IFilterPattern {
313
315
// going through the factory
314
316
for ( const column of columns ) {
315
317
if ( ! validColumnName ( column ) ) {
316
- throw new Error ( `Invalid column name: ${ column } ` ) ;
318
+ throw new UnscopedValidationError ( `Invalid column name: ${ column } ` ) ;
317
319
}
318
320
}
319
321
320
322
if ( sum ( columns . map ( c => c === COL_ELLIPSIS ? 1 : 0 ) ) > 1 ) {
321
- throw new Error ( "Can use at most one '...' column" ) ;
323
+ throw new UnscopedValidationError ( "Can use at most one '...' column" ) ;
322
324
}
323
325
324
326
return new SpaceDelimitedTextPattern ( columns , { } ) ;
@@ -335,10 +337,10 @@ export class SpaceDelimitedTextPattern implements IFilterPattern {
335
337
*/
336
338
public whereString ( columnName : string , comparison : string , value : string ) : SpaceDelimitedTextPattern {
337
339
if ( columnName === COL_ELLIPSIS ) {
338
- throw new Error ( "Can't use '...' in a restriction" ) ;
340
+ throw new UnscopedValidationError ( "Can't use '...' in a restriction" ) ;
339
341
}
340
342
if ( this . columns . indexOf ( columnName ) === - 1 ) {
341
- throw new Error ( `Column in restrictions that is not in columns: ${ columnName } ` ) ;
343
+ throw new UnscopedValidationError ( `Column in restrictions that is not in columns: ${ columnName } ` ) ;
342
344
}
343
345
344
346
comparison = validateStringOperator ( comparison ) ;
@@ -354,10 +356,10 @@ export class SpaceDelimitedTextPattern implements IFilterPattern {
354
356
*/
355
357
public whereNumber ( columnName : string , comparison : string , value : number ) : SpaceDelimitedTextPattern {
356
358
if ( columnName === COL_ELLIPSIS ) {
357
- throw new Error ( "Can't use '...' in a restriction" ) ;
359
+ throw new UnscopedValidationError ( "Can't use '...' in a restriction" ) ;
358
360
}
359
361
if ( this . columns . indexOf ( columnName ) === - 1 ) {
360
- throw new Error ( `Column in restrictions that is not in columns: ${ columnName } ` ) ;
362
+ throw new UnscopedValidationError ( `Column in restrictions that is not in columns: ${ columnName } ` ) ;
361
363
}
362
364
363
365
comparison = validateNumericalOperator ( comparison ) ;
@@ -445,7 +447,7 @@ function validateStringOperator(operator: string) {
445
447
if ( operator === '==' ) { operator = '=' ; }
446
448
447
449
if ( operator !== '=' && operator !== '!=' ) {
448
- throw new Error ( `Invalid comparison operator ('${ operator } '), must be either '=' or '!='` ) ;
450
+ throw new UnscopedValidationError ( `Invalid comparison operator ('${ operator } '), must be either '=' or '!='` ) ;
449
451
}
450
452
451
453
return operator ;
@@ -463,7 +465,7 @@ function validateNumericalOperator(operator: string) {
463
465
if ( operator === '==' ) { operator = '=' ; }
464
466
465
467
if ( VALID_OPERATORS . indexOf ( operator ) === - 1 ) {
466
- throw new Error ( `Invalid comparison operator ('${ operator } '), must be one of ${ VALID_OPERATORS . join ( ', ' ) } ` ) ;
468
+ throw new UnscopedValidationError ( `Invalid comparison operator ('${ operator } '), must be one of ${ VALID_OPERATORS . join ( ', ' ) } ` ) ;
467
469
}
468
470
469
471
return operator ;
@@ -478,7 +480,7 @@ function renderRestriction(column: string, restriction: ColumnRestriction) {
478
480
} else if ( restriction . stringValue ) {
479
481
return `${ column } ${ restriction . comparison } ${ quoteTerm ( restriction . stringValue ) } ` ;
480
482
} else {
481
- throw new Error ( 'Invalid restriction' ) ;
483
+ throw new UnscopedValidationError ( 'Invalid restriction' ) ;
482
484
}
483
485
}
484
486
0 commit comments