ucl/ucl/errors.go
Leon Mika dcd4d0c5d2 Some new features and bugfixes
- Fixed parse bug which would result in an 'unrecognised }' when a comment appeared before a }
- Added support for ${} variables interpolation in strings
- Added support for $() for sub-expression interoplation in strings
- Fixed bug which was preventing dot dereferencing in array and hash literals
- Defined error type for when the result is not convertable to go
2025-01-15 22:07:29 +11:00

43 lines
755 B
Go

package ucl
import (
"errors"
"fmt"
"github.com/alecthomas/participle/v2/lexer"
)
var (
ErrNotConvertable = errors.New("result not convertable to go")
)
var (
tooManyFinallyBlocksError = newBadUsage("try needs at most 1 finally")
)
type errorWithPos struct {
err error
pos lexer.Position
}
func (e errorWithPos) Error() string {
return fmt.Sprintf("%v:%v - %v", e.pos.Line, e.pos.Offset, e.err.Error())
}
func (e errorWithPos) Unwrap() error {
return e.err
}
type errBadUsage struct {
msg string
}
func newBadUsage(msg string) func(pos lexer.Position) error {
return func(pos lexer.Position) error {
return errorWithPos{err: errBadUsage{msg: msg}, pos: pos}
}
}
func (e errBadUsage) Error() string {
return "bad usage: " + e.msg
}