{"record":{"id":"177cf3fb771da0e9","repo":"XTLS/Xray-core","slug":"failed-to-read-config-arg","errorCode":null,"errorMessage":"failed to read config: {arg}","messagePattern":"failed to read config: (.+?)","errorType":"validation","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"main/yaml/yaml.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:      \"YAML\",\n\t\tExtension: []string{\"yaml\", \"yml\"},\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.DecodeYAMLConfig(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.LoadYAMLConfig(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/yaml/yaml.go#L10-L46","documentation":"YAML counterpart of the config-read error: the YAML loader (extensions \"yaml\"/\"yml\") fails when confloader.LoadConfig cannot produce a reader for an argument. Same failure modes as errors 544/549 — missing/unreadable local file or failed http/socket fetch — with the underlying cause chained in Base(err).","triggerScenarios":"xray run -c config.yml where the file is absent, unreadable, or where a URL-form arg could not be fetched.","commonSituations":"Typo between .yaml and .yml extensions, config placed outside the container volume in Docker deployments, SELinux/AppArmor denying service-user reads.","solutions":["Confirm the path in the message; fix extension typos (.yml vs .yaml)","Check read permission for the exact runtime user (sudo -u xray cat config.yml)","In containers, verify the volume mount actually exposes the file","For remote args, inspect the chained fetch error"],"exampleFix":"# before (file is config.yml, flag says config.yaml)\nxray run -c /etc/xray/config.yaml\n\n# after\nxray run -c /etc/xray/config.yml","handlingStrategy":"validation","validationCode":"for _, p := range yamlPaths {\n    if _, err := os.Stat(p); err != nil { return err }\n    if data, err := os.ReadFile(p); err == nil {\n        var v interface{}; if yaml.Unmarshal(data, &v) != nil { return err }\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := startYamlLoad(); err != nil { logPathFromMessage(err); os.Exit(1) }","preventionTips":["Double-check .yaml vs .yml spelling","Mount config volumes read-only into containers","Preflight YAML parse in deploy scripts"],"tags":["go","xray","yaml","config","filesystem"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}