github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/flameql/error.go (about)

     1  package flameql
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  var (
     9  	ErrInvalidQuerySyntax    = errors.New("invalid query syntax")
    10  	ErrInvalidAppName        = errors.New("invalid application name")
    11  	ErrInvalidMatchersSyntax = errors.New("invalid tag matchers syntax")
    12  	ErrInvalidTagKey         = errors.New("invalid tag key")
    13  	ErrInvalidTagValueSyntax = errors.New("invalid tag value syntax")
    14  
    15  	ErrAppNameIsRequired = errors.New("application name is required")
    16  	ErrTagKeyIsRequired  = errors.New("tag key is required")
    17  	ErrTagKeyReserved    = errors.New("tag key is reserved")
    18  
    19  	ErrMatchOperatorIsRequired = errors.New("match operator is required")
    20  	ErrUnknownOp               = errors.New("unknown tag match operator")
    21  )
    22  
    23  type Error struct {
    24  	Inner error
    25  	Expr  string
    26  	// TODO: add offset?
    27  }
    28  
    29  func newErr(err error, expr string) *Error { return &Error{Inner: err, Expr: expr} }
    30  
    31  func (e *Error) Error() string { return e.Inner.Error() + ": " + e.Expr }
    32  
    33  func (e *Error) Unwrap() error { return e.Inner }
    34  
    35  func newInvalidTagKeyRuneError(k string, r rune) *Error {
    36  	return newInvalidRuneError(ErrInvalidTagKey, k, r)
    37  }
    38  
    39  func newInvalidAppNameRuneError(k string, r rune) *Error {
    40  	return newInvalidRuneError(ErrInvalidAppName, k, r)
    41  }
    42  
    43  func newInvalidRuneError(err error, k string, r rune) *Error {
    44  	return newErr(err, fmt.Sprintf("%s: character is not allowed: %q", k, r))
    45  }