{"record":{"id":"47261626bfdd5955","repo":"XTLS/Xray-core","slug":"failed-to-read-config-472616","errorCode":null,"errorMessage":"failed to read config: ","messagePattern":"failed to read config: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main/json/json.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:      \"JSON\",\n\t\tExtension: []string{\"json\"},\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.DecodeJSONConfig(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\tif serial.UseStrictJSON {\n\t\t\t\t\tcfg, err := serial.DecodeJSONConfigStrict(v)\n\t\t\t\t\tif err != nil {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/json/json.go#L10-L46","documentation":"The JSON config loader (registered for the \"json\" format) fails when confloader.LoadConfig cannot produce a reader for one of the argument paths. confloader.LoadConfig dispatches to external.FetchHTTPContent for http(s)/socket-looking targets and to local file reading otherwise, so this error wraps either a network fetch failure or a filesystem error (missing file, permission denied).","triggerScenarios":"Passing a nonexistent path in cmdarg.Arg (e.g. xray run -c ./missing.json), a file without read permission, or a URL-style config target whose fetch failed (dial, status, read errors from errors 541-543 surface here as the chained cause).","commonSituations":"Wrong working directory making a relative config path unresolvable, typos in filenames, running Xray as a service user that cannot read the config, or remote-config URL failures at boot.","solutions":["Confirm the file exists at the exact path printed in the message (it includes the failing arg)","Fix permissions: chmod 644 and ensure the running user owns/can read it","Use absolute paths in service/systemd units where the working directory differs","If the arg is a URL, debug the underlying fetch error (dial/status/read) chained in Base(err)"],"exampleFix":"# before\nxray run -c conf/config.json   # run from another cwd -> failed to read config\n\n# after\nxray run -c /etc/xray/config.json","handlingStrategy":"validation","validationCode":"func configReadable(p string) error { fi, err := os.Stat(p); if err != nil { return err }; if fi.IsDir() { return fmt.Errorf(\"is dir\") }; return nil }\n\nfor _, p := range paths { if err := configReadable(p); err != nil { log.Fatal(err) } }","typeGuard":"func isLoadableArg(v interface{}) bool { _, ok1 := v.(cmdarg.Arg); _, ok2 := v.(io.Reader); return ok1 || ok2 }","tryCatchPattern":"if err := runStartXray(); err != nil && strings.Contains(err.Error(), \"failed to read config\") { os.Exit(1) /* report file from message */ }","preventionTips":["Use absolute config paths, especially in systemd units","Run as the service user when verifying read permission","Keep a pre-deploy step that stats every config path in CI"],"tags":["go","xray","config","filesystem","json"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}