{"record":{"id":"bdb717ed6fcd8937","repo":"kataras/iris","slug":"toml-w-bdb717","errorCode":null,"errorMessage":"toml :%w","messagePattern":"toml :%w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"configuration.go","lineNumber":148,"sourceCode":"\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\n}\n\n// Configurator is just an interface which accepts the framework instance.\n//\n// It can be used to register a custom configuration with `Configure` in order\n// to modify the framework instance.","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/configuration.go#L130-L166","documentation":"iris.TOML() panics with 'toml :%w' when os.ReadFile cannot read the resolved TOML configuration file (file missing, permission denied, or path is a directory). The panic behavior means the application aborts rather than returning a normal error. The wrapped value is the *PathError from os.ReadFile.","triggerScenarios":"Calling iris.TOML(filename) where the file does not exist at the absolute path, lacks read permissions, or is a directory. TestConfigurationTOML exercises this path when the fixture file is absent.","commonSituations":"Deploying without the configuration.yml/.toml file shipped in the image; running the binary from a different working directory than in development so the relative filename resolves elsewhere; Docker containers running as non-root reading root-owned files.","solutions":["Verify the file exists at the path: os.Stat(filepath.Abs(filename)) before calling iris.TOML.","Use an absolute path for the TOML file in deployments, or resolve relative to a known base directory.","Fix file permissions/ownership so the process user can read the file.","Wrap the call in a defer/recover if TOML config is optional and you want a fallback to defaults."],"exampleFix":"// before\nc := iris.TOML(\"configuration.tml\") // panics if missing\n// after\nif _, err := os.Stat(\"configuration.tml\"); err != nil {\n    log.Println(\"no toml config, using defaults\")\n    c := iris.New().Configuration\n} else {\n    c := iris.TOML(\"configuration.tml\")\n}","handlingStrategy":"validation","validationCode":"abs, err := filepath.Abs(filename)\nif err != nil { return err }\nif info, err := os.Stat(abs); err != nil { return fmt.Errorf(\"toml config missing: %w\", err) } else if info.IsDir() { return errors.New(\"toml config path is a directory\") }","typeGuard":null,"tryCatchPattern":"func() (c iris.Configuration) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Printf(\"toml read failed: %v\", r)\n            c = iris.DefaultConfiguration()\n        }\n    }()\n    return iris.TOML(filename)\n}()","preventionTips":["Ship the TOML file inside your container/image and verify in CI","Use absolute paths in production deployments","Check file permissions for the process user","Keep a fallback to default configuration when the file is optional"],"tags":["toml","configuration","file-not-found","panic"],"backgroundTag":"config-file-not-found","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}