{"record":{"id":"01a9b0f6ba3f5ecd","repo":"XTLS/Xray-core","slug":"failed-to-read-config-01a9b0","errorCode":null,"errorMessage":"failed to read config: ","messagePattern":"failed to read config: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main/toml/toml.go","lineNumber":28,"sourceCode":"\t\"github.com/xtls/xray-core/core\"\n\t\"github.com/xtls/xray-core/infra/conf\"\n\t\"github.com/xtls/xray-core/infra/conf/serial\"\n\t\"github.com/xtls/xray-core/main/confloader\"\n)\n\nfunc init() {\n\tcommon.Must(core.RegisterConfigLoader(&core.ConfigFormat{\n\t\tName:      \"TOML\",\n\t\tExtension: []string{\"toml\"},\n\t\tLoader: func(input interface{}) (*core.Config, error) {\n\t\t\tswitch v := input.(type) {\n\t\t\tcase cmdarg.Arg:\n\t\t\t\tcf := &conf.Config{}\n\t\t\t\tfor i, arg := range v {\n\t\t\t\t\terrors.LogInfo(context.Background(), \"Reading config: \", arg)\n\t\t\t\t\tr, err := confloader.LoadConfig(arg)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, errors.New(\"failed to read config: \", arg).Base(err)\n\t\t\t\t\t}\n\t\t\t\t\tc, err := serial.DecodeTOMLConfig(r)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, errors.New(\"failed to decode config: \", arg).Base(err)\n\t\t\t\t\t}\n\t\t\t\t\tif i == 0 {\n\t\t\t\t\t\t// This ensure even if the muti-json parser do not support a setting,\n\t\t\t\t\t\t// It is still respected automatically for the first configure file\n\t\t\t\t\t\t*cf = *c\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tcf.Override(c, arg)\n\t\t\t\t}\n\t\t\t\treturn cf.Build()\n\t\t\tcase io.Reader:\n\t\t\t\treturn serial.LoadTOMLConfig(v)\n\t\t\tdefault:\n\t\t\t\treturn nil, errors.New(\"unknown type\")","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/toml/toml.go#L10-L46","documentation":"TOML counterpart of the JSON read error: the TOML loader (registered for extension \"toml\") fails when confloader.LoadConfig cannot obtain a reader for one of the config arguments. Exactly like error 544 but for the TOML path — the cause is either a filesystem failure (missing/unreadable file) or a failed remote fetch (http/socket target).","triggerScenarios":"xray run -c config.toml where config.toml does not exist, is unreadable by the service user, or where the arg is an http(s)/socket target whose fetch failed.","commonSituations":"Renaming a .json config to .toml without converting content (then hitting decode instead), wrong path in systemd units, permission issues under hardened service users, remote TOML endpoints down.","solutions":["Verify the exact path from the error message exists and is readable (ls -l, run as the service user)","Use absolute paths in service definitions","If remote, debug the fetch cause chained in Base(err) (dial/status/read)","Ensure the file really contains TOML — extension and content must agree"],"exampleFix":"# before\nxray run -c xray.toml   # file actually at /etc/xray/xray.toml\n\n# after\nxray run -c /etc/xray/xray.toml","handlingStrategy":"validation","validationCode":"for _, p := range tomlPaths { if fi, err := os.Stat(p); err != nil || fi.IsDir() { return err } }","typeGuard":null,"tryCatchPattern":"if err := startXray(); err != nil && strings.Contains(err.Error(), \"failed to read config\") { extractFailingArg(err); os.Exit(1) }","preventionTips":["Use absolute .toml paths in service units","Verify readability as the runtime user","Automate TOML linting in CI (taplo)"],"tags":["go","xray","config","toml","filesystem"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}