{"record":{"id":"d3b9927d49d0ad3d","repo":"kataras/iris","slug":"toml-w","errorCode":null,"errorMessage":"toml: %w","messagePattern":"toml: %w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"configuration.go","lineNumber":142,"sourceCode":"// app.Configure(iris.WithConfiguration(iris.TOML(\"myconfig.tml\"))) or\n// app.Run([iris.Runner], iris.WithConfiguration(iris.TOML(\"myconfig.tml\"))).\nfunc TOML(filename string) Configuration {\n\tc := DefaultConfiguration()\n\n\t// check for globe configuration file and use that, otherwise\n\t// return the default configuration if file doesn't exist.\n\tif filename == globalConfigurationKeyword {\n\t\tfilename = homeConfigurationFilename(\".tml\")\n\t\tif _, err := os.Stat(filename); os.IsNotExist(err) {\n\t\t\tpanic(\"default configuration file '\" + filename + \"' does not exist\")\n\t\t}\n\t}\n\n\t// get the abs\n\t// which will try to find the 'filename' from current workind dir too.\n\ttomlAbsPath, err := filepath.Abs(filename)\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"toml: %w\", err))\n\t}\n\n\t// read the raw contents of the file\n\tdata, err := os.ReadFile(tomlAbsPath)\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"toml :%w\", err))\n\t}\n\n\t// put the file's contents as toml to the default configuration(c)\n\tif _, err := toml.Decode(string(data), &c); err != nil {\n\t\tpanic(fmt.Errorf(\"toml :%w\", err))\n\t}\n\t// Author's notes:\n\t// The toml's 'usual thing' for key naming is: the_config_key instead of TheConfigKey\n\t// but I am always prefer to use the specific programming language's syntax\n\t// and the original configuration name fields for external configuration files\n\t// so we do 'toml: \"TheConfigKeySameAsTheConfigField\" instead.\n\treturn c","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/configuration.go#L124-L160","documentation":"The public iris.TOML() loader panics with 'toml: %w' when filepath.Abs(filename) fails to resolve the absolute path of the TOML configuration file. This is rare and typically only happens with an empty filename or OS-level path resolution errors. Unlike the YAML loader, TOML uses panic instead of returning an error.","triggerScenarios":"Calling iris.TOML(filename) where filepath.Abs returns an error — most commonly when filename is an empty string, or when working-directory lookups fail in restricted environments. Called from TestConfigurationTOML and production TOML loading.","commonSituations":"Passing an empty or environment-variable-substituted filename that ends up empty (e.g. TOML_FILE env var not set); running inside a container or chroot where the working directory cannot be resolved.","solutions":["Check that the filename argument is a non-empty string before calling iris.TOML.","Resolve the absolute path yourself with filepath.Abs first and handle the error to avoid the panic.","Recover from the panic with a deferred recover() wrapper if TOML loading is optional.","Verify environment variables feeding the filename are set in the deployment environment."],"exampleFix":"// before\nc := iris.TOML(cfgFile) // panics if cfgFile is \"\"\n// after\nif cfgFile == \"\" {\n    log.Fatal(\"TOML config path is empty\")\n}\nabs, err := filepath.Abs(cfgFile)\nif err != nil {\n    log.Fatalf(\"bad toml path: %v\", err)\n}\nc := iris.TOML(abs)","handlingStrategy":"validation","validationCode":"if filename == \"\" { return errors.New(\"toml config path must not be empty\") }\nif _, err := filepath.Abs(filename); err != nil { return err }","typeGuard":null,"tryCatchPattern":"func() {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Printf(\"toml load failed: %v\", r)\n        }\n    }()\n    c = iris.TOML(filename)\n}()","preventionTips":["Never pass empty strings; default to a known-good filename when env vars are unset","Resolve to an absolute path yourself before calling iris.TOML","Remember iris.TOML panics — do not use in request handlers","Test config loading in the same working directory layout as production"],"tags":["toml","configuration","panic","filepath"],"backgroundTag":"config-file-load-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}