{"record":{"id":"5786dc686edda430","repo":"XTLS/Xray-core","slug":"failed-to-load-config-files","errorCode":null,"errorMessage":"failed to load config files: [","messagePattern":"failed to load config files: \\[","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"main/run.go","lineNumber":221,"sourceCode":"\t\tlog.Println(\"Using config from STDIN\")\n\t}\n\treturn cmdarg.Arg{\"stdin:\"}\n}\n\nfunc getConfigFormat() string {\n\tf := core.GetFormatByExtension(*format)\n\tif f == \"\" {\n\t\tf = \"auto\"\n\t}\n\treturn f\n}\n\nfunc startXray() (core.Server, error) {\n\tconfigFiles := getConfigFilePath(true)\n\n\tc, err := core.LoadConfig(getConfigFormat(), configFiles)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to load config files: [\", configFiles.String(), \"]\").Base(err)\n\t}\n\n\tserver, err := core.New(c)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to create server\").Base(err)\n\t}\n\n\treturn server, nil\n}\n","sourceCodeStart":203,"sourceCodeEnd":231,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/run.go#L203-L231","documentation":"Top-level wrapper thrown by startXray in main/run.go when core.LoadConfig fails for the collected config file list. It aggregates every per-format failure: unreadable files, JSON/TOML/YAML decode errors, and multi-file merge errors from Config.Override. The message includes the full file list and the real cause is chained via Base(err), so the underlying loader error must be read to diagnose.","triggerScenarios":"Any xray run / xray -c invocation where at least one config file cannot be read, parsed, or merged: missing file, syntax error, or conflicting settings between multiple -c files during Override.","commonSituations":"Booting the Xray daemon with a broken config after an edit; passing several configs where a later one overrides incompatibly; wrong -format flag (e.g. forcing json on a yaml file).","solutions":["Look at the chained Base(err) — it points at the exact file and parse/read failure (errors 544/545/549-552)","Run xjson-style validation or xray run -test (if available in your build) to dry-check config","Ensure the -format flag matches the file content, or omit it to use auto-detection by extension","When using multiple configs, verify the later files only override compatible fields"],"exampleFix":"# before\nxray run -format json -c /etc/xray/config.yaml  # yaml parsed as json -> failed to load config files\n\n# after\nxray run -c /etc/xray/config.yaml  # auto-detect by .yaml extension","handlingStrategy":"try-catch","validationCode":"// fail fast before start\nfor _, p := range getConfigFilePaths() {\n    if _, err := os.Stat(p); err != nil { return err }\n}","typeGuard":null,"tryCatchPattern":"if server, err := startXray(); err != nil {\n    log.Fatalf(\"startup failed: %v\", err) // Base(err) names the real file/line cause\n}","preventionTips":["Add a config validation stage (parse all files with the matching loader) to deploy scripts","Keep -format consistent with file extensions or omit it","Pin config schema to your Xray version in docs"],"tags":["go","xray","startup","config","boot-failure"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}