MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / define

Function define

pkg/errors/definitions.go:135–179  ·  view source on GitHub ↗
(code uint32, name, messageFormat string, publicAttributes ...string)

Source from the content-addressed store, hash-verified

133}
134
135func define(code uint32, name, messageFormat string, publicAttributes ...string) *Definition {
136 ns := namespace(3)
137 if code == 0 {
138 code = uint32(codes.Unknown)
139 }
140
141 def := &Definition{
142 namespace: ns,
143 name: name,
144 messageFormat: messageFormat,
145 messageFormatArguments: messageFormatArguments(messageFormat),
146 publicAttributes: publicAttributes,
147 code: code,
148 }
149
150 fullName := def.FullName()
151
152 parsedMessageFormat, err := formatter.Parse(messageFormat)
153 if err != nil {
154 panic(fmt.Errorf("could not parse message format `%s` for %s: %w", messageFormat, fullName, err))
155 }
156 def.parsedMessageFormat = parsedMessageFormat
157
158 // All message format arguments must be public:
159nextArg:
160 for _, arg := range def.messageFormatArguments {
161 for _, attr := range def.publicAttributes {
162 if arg == attr {
163 continue nextArg
164 }
165 }
166 def.publicAttributes = append(def.publicAttributes, arg)
167 }
168
169 def.setGRPCStatus() // store the (marshaled) gRPC status message.
170
171 if registered := registerDefinition(def); registered != def {
172 return registered
173 }
174
175 desc := i18n.Define(fmt.Sprintf("error:%s", fullName), def.messageFormat)
176 desc.SetSource(2)
177
178 return def
179}
180
181var (
182 definitions = make(map[string]*Definition)

Callers 15

DefineFunction · 0.85
DefineInvalidArgumentFunction · 0.85
DefineDeadlineExceededFunction · 0.85
DefineCanceledFunction · 0.85
DefineNotFoundFunction · 0.85
DefineAlreadyExistsFunction · 0.85
DefinePermissionDeniedFunction · 0.85
DefineResourceExhaustedFunction · 0.85
DefineFailedPreconditionFunction · 0.85
DefineAbortedFunction · 0.85
DefineUnimplementedFunction · 0.85
DefineInternalFunction · 0.85

Calls 9

FullNameMethod · 0.95
setGRPCStatusMethod · 0.95
DefineFunction · 0.92
namespaceFunction · 0.85
messageFormatArgumentsFunction · 0.85
registerDefinitionFunction · 0.85
SetSourceMethod · 0.80
ParseMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected