{"record":{"id":"96c97be911f1da91","repo":"XTLS/Xray-core","slug":"failed-to-decode-config-arg-96c97b","errorCode":null,"errorMessage":"failed to decode config: {arg}","messagePattern":"failed to decode config: (.+?)","errorType":"validation","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"main/yaml/yaml.go","lineNumber":32,"sourceCode":")\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\")\n\t\t\t}\n\t\t},\n\t}))\n}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/yaml/yaml.go#L14-L50","documentation":"The YAML loader read the input but serial.DecodeYAMLConfig failed to unmarshal it into Xray's *conf.Config structure. Covers YAML syntax errors (bad indentation, tabs, unquoted special characters) and type/structure mismatches; the decoder message with line numbers is chained as the Base cause.","triggerScenarios":"Tabs used for indentation (YAML forbids them), port as quoted string where an int is required, duplicated keys, or mapping structure that does not match the config schema.","commonSituations":"Hand-indenting nested inbounds/settings and misaligning by one space; unquoted 'on'/'no'/'443:' style scalars parsed as wrong YAML types; copying JSON-shaped structure into YAML without converting braces to indentation.","solutions":["Validate with a YAML linter (yamllint, online parsers) to get exact line of the syntax error","Quote ambiguous scalars; ensure ports are plain integers, booleans are true/false","Indent with spaces only, consistently 2 per level; no tabs anywhere","Cross-check top-level keys (inbounds, outbounds, routing, ...) against the schema"],"exampleFix":"# before\ninbounds:\n  - port: \"443\"\n    protocol: dokodemo-door\n\n# after\ninbounds:\n  - port: 443\n    protocol: dokodemo-door","handlingStrategy":"validation","validationCode":"import \"gopkg.in/yaml.v3\"\nvar v map[string]interface{}\nif err := yaml.Unmarshal(data, &v); err != nil { log.Fatalf(\"yaml syntax: %v\", err) } // run before xray","typeGuard":null,"tryCatchPattern":"if err := loadYaml(); err != nil {\n    var typ *yaml.TypeError\n    if errors.As(err, &typ) { for _, line := range typ.Line { report(line) } }\n}","preventionTips":["Run yamllint (tabs forbidden, indentation consistency) in CI","Quote ambiguous scalar values","Convert JSON configs with a tool instead of by hand"],"tags":["go","xray","yaml","config","parsing"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}