I have started experimenting with a feature that requires returning an error the to user if a when cedar expression is invalid. At the moment I use something like this to test the expression.
selectorPolicy, err := cedar.NewPolicySet("", []byte(fmt.Sprintf(`permit(principal,action,resource) when { %s };`, whenExpression)))
I would like to be able to use the error result programatically to provide feedback about the exact error position and details. Likely adding some syntax highlighting in my app.
The errors returned by the current version of the parser use fmt.Errorf(), if this was swapped for a struct alongs the lines of this, it could be used to extract the exact details of the error.
type ScanError struct {
Message string
Position Position
}
func (e ScanError) Error() string {
return fmt.Sprintf("%v: %s", e.Position, e.Message)
}
func (s *scanner) error(msg string) {
s.tokEnd = s.srcPos - s.lastCharLen // make sure token text is terminated
s.err = ScanError{
Message: msg,
Position: s.position,
}
}
I'm happy to contribute some code here, though I note you have some recent work pending to stabilise the AST and parsing code so will hold off for now.
Edit: I see that the new version v0.2.0 has been released to I will check that out and see if there is a way forward here :)
I have started experimenting with a feature that requires returning an error the to user if a
whencedar expression is invalid. At the moment I use something like this to test the expression.I would like to be able to use the error result programatically to provide feedback about the exact error position and details. Likely adding some syntax highlighting in my app.
The errors returned by the current version of the parser use fmt.Errorf(), if this was swapped for a struct alongs the lines of this, it could be used to extract the exact details of the error.
I'm happy to contribute some code here, though I note you have some recent work pending to stabilise the AST and parsing code so will hold off for now.
Edit: I see that the new version v0.2.0 has been released to I will check that out and see if there is a way forward here :)