{"record":{"id":"135bbd654fa77a84","repo":"XTLS/Xray-core","slug":"both-file-and-bytes-are-empty","errorCode":null,"errorMessage":"both file and bytes are empty.","messagePattern":"both file and bytes are empty\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/transport_method.go","lineNumber":813,"sourceCode":"\tconfig.MasqString = c.Masquerade.Content\n\tconfig.MasqStringHeaders = c.Masquerade.Headers\n\tconfig.MasqStringStatusCode = c.Masquerade.StatusCode\n\n\tif config.UdpIdleTimeout == 0 {\n\t\tconfig.UdpIdleTimeout = 60\n\t}\n\n\treturn config, nil\n}\n\nfunc readFileOrString(f string, s []string) ([]byte, error) {\n\tif len(f) > 0 {\n\t\treturn filesystem.ReadCert(f)\n\t}\n\tif len(s) > 0 {\n\t\treturn []byte(strings.Join(s, \"\\n\")), nil\n\t}\n\treturn nil, errors.New(\"both file and bytes are empty.\")\n}\n","sourceCodeStart":795,"sourceCodeEnd":815,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/transport_method.go#L795-L815","documentation":"Thrown by readFileOrString when building transport security: the caller asked for certificate/key material but both the file path (f) and the inline string array (s) are empty. The helper prefers the file, falls back to joined inline lines, and errors only when neither is present.","triggerScenarios":"A streamSettings.tlsSettings.certificates entry with neither \"certificateFile\" nor \"certificate\" (and similarly for keys) — e.g. an empty {} object in the certificates array.","commonSituations":"Template configs that pre-create an empty certificates placeholder, or YAML/JSON merges dropping the cert fields while leaving the object.","solutions":["Add \"certificateFile\" pointing to an existing PEM file, or inline the PEM under \"certificate\": [\"-----BEGIN CERTIFICATE-----\", ...].","Remove the empty certificates entry if TLS is not intended.","Verify the file path is accessible by the process (absolute paths are safest)."],"exampleFix":"// before\n\"certificates\": [{}]\n// after\n\"certificates\": [{ \"certificateFile\": \"/etc/xray/cert.pem\", \"keyFile\": \"/etc/xray/key.pem\" }]","handlingStrategy":"validation","validationCode":"for _, cert := range tls.Certificates {\n    if cert.CertificateFile == \"\" && len(cert.Certificate) == 0 {\n        return errors.New(\"tls certificate entry missing both file and inline bytes\")\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := secCfg.Build(); err != nil && strings.Contains(err.Error(), \"both file and bytes are empty\") {\n    return errors.New(\"remove or fill the empty tls certificates[] entry\")\n}","preventionTips":["Drop empty certificate placeholders when generating configs.","Run 'xray run -test' (config check) before deploying."],"tags":["config","tls","certificates","filesystem","validation","go"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}