github.com/MontFerret/ferret@v0.18.0/pkg/runtime/expressions/suppressible.go (about)

     1  package expressions
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/MontFerret/ferret/pkg/runtime/core"
     7  	"github.com/MontFerret/ferret/pkg/runtime/values"
     8  )
     9  
    10  type SuppressibleExpression struct {
    11  	exp core.Expression
    12  }
    13  
    14  func SuppressErrors(exp core.Expression) (core.Expression, error) {
    15  	if exp == nil {
    16  		return nil, core.Error(core.ErrMissedArgument, "expression")
    17  	}
    18  
    19  	return &SuppressibleExpression{exp}, nil
    20  }
    21  
    22  func (exp *SuppressibleExpression) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) {
    23  	return exp.Maybe(exp.exp.Exec(ctx, scope))
    24  }
    25  
    26  func (exp *SuppressibleExpression) Maybe(value core.Value, err error) (core.Value, error) {
    27  	if err != nil {
    28  		return values.None, nil
    29  	}
    30  
    31  	return value, nil
    32  }