1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-11-29 22:17:29 +02:00
Files
ferret/pkg/runtime/expressions/suppressible.go
Tim Voronov 2f399c669e Added support of error supression to inline expressions (#671)
* Added support of error supression to inline expressions
2021-09-20 00:53:00 -04:00

33 lines
712 B
Go

package expressions
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
type SuppressibleExpression struct {
exp core.Expression
}
func SuppressErrors(exp core.Expression) (core.Expression, error) {
if exp == nil {
return nil, core.Error(core.ErrMissedArgument, "expression")
}
return &SuppressibleExpression{exp}, nil
}
func (exp *SuppressibleExpression) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) {
return exp.Maybe(exp.exp.Exec(ctx, scope))
}
func (exp *SuppressibleExpression) Maybe(value core.Value, err error) (core.Value, error) {
if err != nil {
return values.None, nil
}
return value, nil
}