github.com/Jeffail/benthos/v3@v3.65.0/public/bloblang/parse_error.go (about)

     1  package bloblang
     2  
     3  import "github.com/Jeffail/benthos/v3/internal/bloblang/parser"
     4  
     5  // ParseError is a structured error type for Bloblang parser errors that
     6  // provides access to information such as the line and column where the error
     7  // occurred.
     8  type ParseError struct {
     9  	Line   int
    10  	Column int
    11  
    12  	input []rune
    13  	iErr  *parser.Error
    14  }
    15  
    16  // Error returns a single line error string.
    17  func (p *ParseError) Error() string {
    18  	return p.iErr.Error()
    19  }
    20  
    21  // ErrorMultiline returns an error string spanning multiple lines that provides
    22  // a cleaner view of the specific error.
    23  func (p *ParseError) ErrorMultiline() string {
    24  	return p.iErr.ErrorAtPositionStructured("", p.input)
    25  }
    26  
    27  func internalToPublicParserError(input []rune, p *parser.Error) *ParseError {
    28  	pErr := &ParseError{
    29  		input: input,
    30  		iErr:  p,
    31  	}
    32  	pErr.Line, pErr.Column = parser.LineAndColOf(input, p.Input)
    33  	return pErr
    34  }