forked from influxdata/flux
/
die.go
37 lines (32 loc) · 885 Bytes
/
die.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package universe
import (
"context"
"github.com/InfluxCommunity/flux"
"github.com/InfluxCommunity/flux/codes"
"github.com/InfluxCommunity/flux/interpreter"
"github.com/InfluxCommunity/flux/runtime"
"github.com/InfluxCommunity/flux/values"
)
const DieKind = "die"
func init() {
runtime.RegisterPackageValue("universe", DieKind, Die())
}
func Die() values.Function {
return values.NewFunction(
DieKind,
runtime.MustLookupBuiltinType("universe", DieKind),
func(ctx context.Context, args values.Object) (values.Value, error) {
return interpreter.DoFunctionCallContext(func(ctx context.Context, args interpreter.Arguments) (values.Value, error) {
msg, err := args.GetRequiredString("msg")
if err != nil {
return nil, err
} else {
return nil, &flux.Error{
Code: codes.Invalid,
Msg: msg,
}
}
}, ctx, args)
}, false,
)
}