ucl/ucl/errors.go
Leon Mika e2f471c608
All checks were successful
Build / build (push) Successful in 2m20s
Added setting of index values
2025-06-14 02:52:03 +02:00

47 lines
988 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")
notIndexableError = newBadUsage("index only support on lists and hashes")
notModIndexableError = newBadUsage("list or hash cannot be modified")
assignToNilIndex = newBadUsage("assigning to nil index value")
)
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
}