{"record":{"id":"b40875b35f7006fd","repo":"XTLS/Xray-core","slug":"unknown-type-b40875","errorCode":null,"errorMessage":"unknown type","messagePattern":"unknown type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main/json/json.go","lineNumber":53,"sourceCode":"\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 {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t\treturn cfg.Build()\n\t\t\t\t}\n\t\t\t\treturn serial.LoadJSONConfig(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}\n","sourceCodeStart":35,"sourceCodeEnd":58,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/json/json.go#L35-L58","documentation":"The JSON config loader's default switch branch: it was invoked with an input that is neither cmdarg.Arg (the string-slice of file paths Xray passes from the CLI) nor io.Reader. This is an API-misuse error for code that calls core.LoadConfig programmatically; the CLI itself never triggers it. There is no Base cause — the type is simply unsupported.","triggerScenarios":"Calling the registered Loader (via core.LoadConfig(\"json\", ...)) with e.g. a []string instead of cmdarg.Arg, a *os.File, a byte slice, or any other type.","commonSituations":"Embedding Xray as a library and passing a raw string or []string of paths; wrapping the loader with a custom front-end that reads config into memory and hands over the wrong type.","solutions":["Convert to cmdarg.Arg before calling: cmdarg.Arg is just []string, so wrap it","If you have stream content, pass an io.Reader (bytes.NewReader(data)) instead","Prefer the high-level core.LoadConfig(format, file, input) API, which handles accepted types"],"exampleFix":"// before\nc, err := core.LoadConfig(\"json\", nil, []string{\"/etc/xray/config.json\"}) // -> unknown type\n\n// after\nimport \"github.com/xtls/xray-core/main/cmdarg\"\nc, err := core.LoadConfig(\"json\", nil, cmdarg.Arg{\"/etc/xray/config.json\"})","handlingStrategy":"type-guard","validationCode":"if _, ok := input.(cmdarg.Arg); !ok {\n    if r, ok := input.(io.Reader); !ok { input = strings.NewReader(string(input.(string))) }\n}","typeGuard":"func isSupportedLoaderInput(v interface{}) bool {\n    switch v.(type) {\n    case cmdarg.Arg, io.Reader: return true\n    default: return false\n    }\n}","tryCatchPattern":"if !isSupportedLoaderInput(input) { return fmt.Errorf(\"pass cmdarg.Arg or io.Reader, got %T\", input) }","preventionTips":["When embedding Xray, always convert paths with cmdarg.Arg{...}","Wrap the loader call behind your own typed API","Unit-test the programmatic config path in CI so type misuse is caught early"],"tags":["go","xray","api-misuse","config","type-error"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}