{"record":{"id":"c7588626adcf0b1b","repo":"benbjohnson/litestream","slug":"failed-to-marshal-request-w-c75886","errorCode":null,"errorMessage":"failed to marshal request: %w","messagePattern":"failed to marshal request: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/start.go","lineNumber":60,"sourceCode":"\n\t// Create HTTP client that connects via Unix socket with timeout\n\tclientTimeout := time.Duration(*timeout) * time.Second\n\tclient := &http.Client{\n\t\tTimeout: clientTimeout,\n\t\tTransport: &http.Transport{\n\t\t\tDialContext: func(_ context.Context, _, _ string) (net.Conn, error) {\n\t\t\t\treturn net.DialTimeout(\"unix\", *socketPath, clientTimeout)\n\t\t\t},\n\t\t},\n\t}\n\n\treq := litestream.StartRequest{\n\t\tPath:    dbPath,\n\t\tTimeout: *timeout,\n\t}\n\treqBody, err := json.Marshal(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal request: %w\", err)\n\t}\n\n\tresp, err := client.Post(\"http://localhost/start\", \"application/json\", bytes.NewReader(reqBody))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to connect to control socket: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read response: %w\", err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tvar errResp litestream.ErrorResponse\n\t\tif err := json.Unmarshal(body, &errResp); err == nil && errResp.Error != \"\" {\n\t\t\treturn fmt.Errorf(\"start failed: %s\", errResp.Error)\n\t\t}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/start.go#L42-L78","documentation":"`litestream start` builds a litestream.StartRequest{Path, Timeout} and serializes it with json.Marshal before POSTing to the control socket at http://localhost/start. If marshaling fails, Run returns 'failed to marshal request' wrapping the json error. In practice this is nearly impossible for this fixed struct (all fields are JSON-encodable), so it almost always indicates an environment/runtime-level problem rather than bad user input.","triggerScenarios":"json.Marshal returning an error for the StartRequest value. With the fixed struct (string Path, int Timeout) this only occurs under exotic runtime conditions such as memory allocation failure; it cannot be triggered by user-supplied values since both fields are plain encodable types.","commonSituations":"Extremely rare — encountered only during system-level resource exhaustion (OOM conditions) or a corrupted Go runtime; not caused by configuration or user input.","solutions":["Retry the command — the failure is transient if caused by memory pressure","Free system memory / check dmesg for OOM killer activity if it recurs","If it persists, rebuild litestream (`go build -o bin/litestream ./cmd/litestream`) to rule out a corrupted binary","Report to litestream issues if reproducible, including the wrapped json error text"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// CLI wrapper: distinguish usage errors from transient failures\nif err := litestreamStart(dbPath, timeout); err != nil {\n\tif strings.Contains(err.Error(), \"failed to marshal request\") {\n\t\t// transient/runtime-level: retry once, then report with wrapped cause\n\t\tif retryErr := litestreamStart(dbPath, timeout); retryErr != nil {\n\t\t\treturn fmt.Errorf(\"start failed after retry: %w\", retryErr)\n\t\t}\n\t\treturn nil\n\t}\n\treturn err\n}","preventionTips":["No input validation can prevent this — the struct is fixed and encodable","Monitor system memory if you see this error recur","Keep the litestream binary rebuilt from a clean checkout","Include the wrapped json error text in bug reports"],"tags":["json","ipc","cli","internal"],"backgroundTag":"json-marshal-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}