{"record":{"id":"cddeb5a1d54d5f3d","repo":"kataras/iris","slug":"panic-err-cddeb5","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"auth/configuration.go","lineNumber":189,"sourceCode":"\t\treturn yaml.Unmarshal(contents, c)\n\t}\n}\n\n// ToYAML returns the \"c\" Configuration's contents as raw yaml byte slice.\nfunc (c *Configuration) ToYAML() ([]byte, error) {\n\treturn yaml.Marshal(c)\n}\n\n// ToJSON returns the \"c\" Configuration's contents as raw json byte slice.\nfunc (c *Configuration) ToJSON() ([]byte, error) {\n\treturn json.Marshal(c)\n}\n\n// MustGenerateConfiguration calls the Configuration's BindRandom\n// method and returns the result. It panics on errors.\nfunc MustGenerateConfiguration() (c Configuration) {\n\tif err := c.BindRandom(); err != nil {\n\t\tpanic(err)\n\t}\n\n\treturn\n}\n\n// MustLoadConfiguration same as LoadConfiguration package-level function\n// but it panics on error.\nfunc MustLoadConfiguration(filename string) Configuration {\n\tc, err := LoadConfiguration(filename)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\treturn c\n}\n\n// LoadConfiguration reads a filename (fullpath)\n// and returns a Configuration binded to the contents of the given filename.","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/auth/configuration.go#L171-L207","documentation":"auth.MustGenerateConfiguration calls Configuration.BindRandom to produce a Configuration with randomized secret values and panics if BindRandom fails. It is a convenience helper meant for generating a starting configuration file.","triggerScenarios":"Calling auth.Configuration.MustGenerateConfiguration() (directly or indirectly via BindFile when a config must be generated) when BindRandom returns an error, typically a marshaling/encoding failure while building the random configuration.","commonSituations":"Bootstrapping a new project's auth config in a constrained environment where the random generation or file encoding step fails.","solutions":["Inspect the panic error from BindRandom and fix whatever encoding/environment issue caused it.","Generate the configuration once in a controlled environment and commit the resulting file instead of regenerating at every startup.","Use the non-panicking BindRandom directly and handle the error if generation may legitimately fail."],"exampleFix":"// before\ncfg := auth.MustGenerateConfiguration() // panics\n// after\nvar cfg auth.Configuration\nif err := cfg.BindRandom(); err != nil { log.Fatal(err) }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"func genConfigSafe() (c auth.Configuration, err error) {\n  defer func() {\n    if r := recover(); r != nil { err = fmt.Errorf(\"MustGenerateConfiguration: %v\", r) }\n  }()\n  return auth.MustGenerateConfiguration(), nil\n}","preventionTips":["Generate configs in a controlled build/dev step, not at every startup","Call BindRandom directly to handle errors explicitly"],"tags":["go","panic","config","bootstrap"],"backgroundTag":"config-generation-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}