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

Function registerDefinition

pkg/errors/definitions.go:186–213  ·  view source on GitHub ↗
(def *Definition)

Source from the content-addressed store, hash-verified

184)
185
186func registerDefinition(def *Definition) *Definition {
187 definitionsMu.Lock()
188 defer definitionsMu.Unlock()
189 fullName := def.FullName()
190 if existing := definitions[fullName]; existing != nil {
191 if existing.code != def.code {
192 panic(fmt.Errorf(
193 "error %s with code %d already defined with code %d",
194 fullName, def.code, existing.code,
195 ))
196 }
197 if existing.messageFormat != def.messageFormat {
198 panic(fmt.Errorf(
199 "error %s with message format %q already defined with message format %q",
200 fullName, def.messageFormat, existing.messageFormat,
201 ))
202 }
203 if !reflect.DeepEqual(existing.publicAttributes, def.publicAttributes) {
204 panic(fmt.Errorf(
205 "error %s with public attributes %q already defined with public attributes %q",
206 fullName, def.publicAttributes, existing.publicAttributes,
207 ))
208 }
209 return existing
210 }
211 definitions[fullName] = def
212 return def
213}
214
215// Define defines a registered error of type Unknown.
216func Define(name, messageFormat string, publicAttributes ...string) *Definition {

Callers 1

defineFunction · 0.85

Calls 2

FullNameMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected