1+ import  {  UnscopedValidationError  }  from  '../../core' ; 
2+ 
13// Implementation of metric patterns 
24
35/** 
@@ -180,7 +182,7 @@ export class FilterPattern {
180182   * A JSON log pattern that matches if all given JSON log patterns match 
181183   */ 
182184  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.' ) ;  } 
184186    if  ( patterns . length  ===  1 )  {  return  patterns [ 0 ] ;  } 
185187    return  new  JSONAggregatePattern ( '&&' ,  patterns ) ; 
186188  } 
@@ -189,7 +191,7 @@ export class FilterPattern {
189191   * A JSON log pattern that matches if any of the given JSON log patterns match 
190192   */ 
191193  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' ) ;  } 
193195    if  ( patterns . length  ===  1 )  {  return  patterns [ 0 ] ;  } 
194196    return  new  JSONAggregatePattern ( '||' ,  patterns ) ; 
195197  } 
@@ -282,7 +284,7 @@ class JSONPostfixPattern extends JsonPattern {
282284class  JSONAggregatePattern  extends  JsonPattern  { 
283285  public  constructor ( operator : string ,  patterns : JsonPattern [ ] )  { 
284286    if  ( operator  !==  '&&'  &&  operator  !==  '||' )  { 
285-       throw  new  Error ( 'Operator must be one of && or ||' ) ; 
287+       throw  new  UnscopedValidationError ( 'Operator must be one of && or ||' ) ; 
286288    } 
287289
288290    const  clauses  =  patterns . map ( p  =>  '('  +  p . jsonPatternString  +  ')' ) ; 
@@ -313,12 +315,12 @@ export class SpaceDelimitedTextPattern implements IFilterPattern {
313315    // going through the factory 
314316    for  ( const  column  of  columns )  { 
315317      if  ( ! validColumnName ( column ) )  { 
316-         throw  new  Error ( `Invalid column name: ${ column }  ) ; 
318+         throw  new  UnscopedValidationError ( `Invalid column name: ${ column }  ) ; 
317319      } 
318320    } 
319321
320322    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" ) ; 
322324    } 
323325
324326    return  new  SpaceDelimitedTextPattern ( columns ,  { } ) ; 
@@ -335,10 +337,10 @@ export class SpaceDelimitedTextPattern implements IFilterPattern {
335337   */ 
336338  public  whereString ( columnName : string ,  comparison : string ,  value : string ) : SpaceDelimitedTextPattern  { 
337339    if  ( columnName  ===  COL_ELLIPSIS )  { 
338-       throw  new  Error ( "Can't use '...' in a restriction" ) ; 
340+       throw  new  UnscopedValidationError ( "Can't use '...' in a restriction" ) ; 
339341    } 
340342    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 }  ) ; 
342344    } 
343345
344346    comparison  =  validateStringOperator ( comparison ) ; 
@@ -354,10 +356,10 @@ export class SpaceDelimitedTextPattern implements IFilterPattern {
354356   */ 
355357  public  whereNumber ( columnName : string ,  comparison : string ,  value : number ) : SpaceDelimitedTextPattern  { 
356358    if  ( columnName  ===  COL_ELLIPSIS )  { 
357-       throw  new  Error ( "Can't use '...' in a restriction" ) ; 
359+       throw  new  UnscopedValidationError ( "Can't use '...' in a restriction" ) ; 
358360    } 
359361    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 }  ) ; 
361363    } 
362364
363365    comparison  =  validateNumericalOperator ( comparison ) ; 
@@ -445,7 +447,7 @@ function validateStringOperator(operator: string) {
445447  if  ( operator  ===  '==' )  {  operator  =  '=' ;  } 
446448
447449  if  ( operator  !==  '='  &&  operator  !==  '!=' )  { 
448-     throw  new  Error ( `Invalid comparison operator ('${ operator }  ) ; 
450+     throw  new  UnscopedValidationError ( `Invalid comparison operator ('${ operator }  ) ; 
449451  } 
450452
451453  return  operator ; 
@@ -463,7 +465,7 @@ function validateNumericalOperator(operator: string) {
463465  if  ( operator  ===  '==' )  {  operator  =  '=' ;  } 
464466
465467  if  ( VALID_OPERATORS . indexOf ( operator )  ===  - 1 )  { 
466-     throw  new  Error ( `Invalid comparison operator ('${ operator } ${ VALID_OPERATORS . join ( ', ' ) }  ) ; 
468+     throw  new  UnscopedValidationError ( `Invalid comparison operator ('${ operator } ${ VALID_OPERATORS . join ( ', ' ) }  ) ; 
467469  } 
468470
469471  return  operator ; 
@@ -478,7 +480,7 @@ function renderRestriction(column: string, restriction: ColumnRestriction) {
478480  }  else  if  ( restriction . stringValue )  { 
479481    return  `${ column } ${ restriction . comparison } ${ quoteTerm ( restriction . stringValue ) }  ; 
480482  }  else  { 
481-     throw  new  Error ( 'Invalid restriction' ) ; 
483+     throw  new  UnscopedValidationError ( 'Invalid restriction' ) ; 
482484  } 
483485} 
484486
0 commit comments