{"record":{"id":"ae0a33c6bde9a7fc","repo":"kataras/iris","slug":"w-example-s","errorCode":null,"errorMessage":"%w: example:\n\n%s","messagePattern":"%w: example:\n\n(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"auth/configuration.go","lineNumber":152,"sourceCode":"\t\t\t},\n\t\t},\n\t}\n\n\treturn nil\n}\n\n// BindFile binds a filename (fullpath) to \"c\" Configuration.\n// The file format is either JSON or YAML and it should be suffixed\n// with .json or .yml/.yaml.\nfunc (c *Configuration) BindFile(filename string) error {\n\tswitch filepath.Ext(filename) {\n\tcase \".json\":\n\t\tcontents, err := os.ReadFile(filename)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\t\tgeneratedConfig := MustGenerateConfiguration()\n\t\t\t\tif generatedYAML, gErr := generatedConfig.ToJSON(); gErr == nil {\n\t\t\t\t\terr = fmt.Errorf(\"%w: example:\\n\\n%s\", err, generatedYAML)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn err\n\t\t}\n\n\t\treturn json.Unmarshal(contents, c)\n\tdefault:\n\t\tcontents, err := os.ReadFile(filename)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\t\tgeneratedConfig := MustGenerateConfiguration()\n\t\t\t\tif generatedYAML, gErr := generatedConfig.ToYAML(); gErr == nil {\n\t\t\t\t\terr = fmt.Errorf(\"%w: example:\\n\\n%s\", err, generatedYAML)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn err\n\t\t}\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/auth/configuration.go#L134-L170","documentation":"auth.Configuration.BindFile wraps the os.ReadFile error with an appended example configuration when the JSON file being bound does not exist (auth/configuration.go:152). The library reads the requested .json file, and on os.ErrNotExist it generates a random sample configuration (MustGenerateConfiguration), marshals it to JSON, and embeds it in the error so the developer can copy a valid file. The underlying cause is a file-not-found error for the given path.","triggerScenarios":"Calling LoadConfiguration/MustLoadConfiguration or Configuration.BindFile with a path ending in .json that does not exist on disk (wrong path, wrong working directory, file not deployed with the app).","commonSituations":"Relative path resolved from an unexpected working directory (e.g. running tests or a systemd service from a different dir); Docker image built without copying the auth config; typo in filename or extension; config file mounted at a different path in Kubernetes.","solutions":["Create the missing JSON file at the given path — the error message itself contains a ready-to-use example JSON configuration you can copy (keys contain random values; replace with your own persisted keys).","Pass an absolute path or resolve the path from a known base (executable dir / env var) instead of relying on the process working directory.","Check the file is included in your deployment (Dockerfile COPY, k8s ConfigMap/volume mount).","Alternatively, skip the file and call cfg.BindRandom() to generate keys in memory (note: keys won't persist across restarts)."],"exampleFix":"// before\ncfg, err := auth.LoadConfiguration(\"auth.json\") // open auth.json: no such file or directory\n\n// after (resolve relative to executable)\nexe, _ := os.Executable()\ncfg, err := auth.LoadConfiguration(filepath.Join(filepath.Dir(exe), \"auth.json\"))","handlingStrategy":"validation","validationCode":"func fileReadable(path string) error {\n    if filepath.Ext(path) != \".json\" {\n        return fmt.Errorf(\"%q is not a .json auth config\", path)\n    }\n    if _, err := os.Stat(path); err != nil {\n        return fmt.Errorf(\"auth config not accessible: %w\", err)\n    }\n    return nil\n}\n// call before BindFile/LoadConfiguration","typeGuard":null,"tryCatchPattern":"var cfg auth.Configuration\nif err := cfg.BindFile(\"auth.json\"); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && errors.Is(perr.Err, fs.ErrNotExist) {\n        // error text already embeds an example JSON config; log it and/or generate one\n        log.Println(err)\n        if gerr := cfg.BindRandom(); gerr == nil {\n            log.Println(\"generated random auth configuration in memory\")\n        }\n    } else {\n        log.Fatalf(\"bind auth config: %v\", err)\n    }\n}","preventionTips":["Use absolute paths built from os.Executable() or a config env var, never bare relative filenames.","Ship the auth config file in your image/deployment and assert its presence in a startup check.","Commit a template auth.json (with placeholder keys) to the repo so a valid file always exists in dev.","Check errors with errors.Is(err, fs.ErrNotExist) to distinguish missing-file from other failures."],"tags":["go","configuration","file-not-found","json"],"backgroundTag":"file-not-found","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}