MCPcopy Create free account
hub / github.com/goadesign/goa / Error

Function Error

dsl/error.go:86–112  ·  view source on GitHub ↗

Error describes a method error return value. The description includes a unique name (in the scope of the method), an optional type, description and DSL that further describes the type. If no type is specified then the built-in ErrorResult type is used. The DSL syntax is identical to the Attribute DS

(name string, args ...any)

Source from the content-addressed store, hash-verified

84// })
85// })
86func Error(name string, args ...any) {
87 if len(args) == 0 {
88 args = []any{expr.ErrorResult}
89 }
90 dt, desc, fn := parseAttributeArgs(nil, args...)
91 att := &expr.AttributeExpr{
92 Description: desc,
93 Type: dt,
94 }
95 if fn != nil {
96 eval.Execute(fn, att)
97 }
98 if att.Type == nil {
99 att.Type = expr.ErrorResult
100 }
101 erro := &expr.ErrorExpr{AttributeExpr: att, Name: name}
102 switch actual := eval.Current().(type) {
103 case *expr.APIExpr:
104 expr.Root.Errors = append(expr.Root.Errors, erro)
105 case *expr.ServiceExpr:
106 actual.Errors = append(actual.Errors, erro)
107 case *expr.MethodExpr:
108 actual.Errors = append(actual.Errors, erro)
109 default:
110 eval.IncompatibleDSL()
111 }
112}
113
114// ErrorName identifies the attribute of a custom error type used to select the
115// returned error response when multiple errors of that type are defined on the

Callers 10

result_dsls.goFile · 0.50
server_dsls.goFile · 0.50
payload_dsls.goFile · 0.50
dsls.goFile · 0.50
dsl_spec_test.goFile · 0.50
service_dsls.goFile · 0.50

Calls 4

ExecuteFunction · 0.92
CurrentFunction · 0.92
IncompatibleDSLFunction · 0.92
parseAttributeArgsFunction · 0.85

Tested by 1