{"record":{"id":"e492076f48c0476a","repo":"AlistGo/alist","slug":"failed-to-create-http-request-w","errorCode":null,"errorMessage":"failed to create HTTP request: %w","messagePattern":"failed to create HTTP request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/proton_drive/util.go","lineNumber":639,"sourceCode":"\t\tSize:     srcObj.GetSize(),\n\t\tModified: srcObj.ModTime(),\n\t\tIsFolder: srcObj.IsDir(),\n\t}, nil\n}\n\nfunc (d *ProtonDrive) executeRenameAPI(ctx context.Context, linkID string, req RenameRequest) error {\n\n\trenameURL := fmt.Sprintf(d.apiBase+\"/drive/v2/volumes/%s/links/%s/rename\",\n\t\td.MainShare.VolumeID, linkID)\n\n\treqBody, err := json.Marshal(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal rename request: %w\", err)\n\t}\n\n\thttpReq, err := http.NewRequestWithContext(ctx, \"PUT\", renameURL, bytes.NewReader(reqBody))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create HTTP request: %w\", err)\n\t}\n\n\thttpReq.Header.Set(\"Content-Type\", \"application/json\")\n\thttpReq.Header.Set(\"Accept\", d.protonJson)\n\thttpReq.Header.Set(\"X-Pm-Appversion\", d.webDriveAV)\n\thttpReq.Header.Set(\"X-Pm-Drive-Sdk-Version\", d.sdkVersion)\n\thttpReq.Header.Set(\"X-Pm-Uid\", d.credentials.UID)\n\thttpReq.Header.Set(\"Authorization\", \"Bearer \"+d.credentials.AccessToken)\n\n\tclient := &http.Client{}\n\tresp, err := client.Do(httpReq)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to execute rename request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"rename failed with status %d\", resp.StatusCode)","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/proton_drive/util.go#L621-L657","documentation":"http.NewRequestWithContext rejected the PUT request for the rename endpoint before any network I/O. Go only errors here for a malformed method, an unparseable URL, or a nil body reader misuse — the URL is built with fmt.Sprintf from d.apiBase, VolumeID and LinkID, so bad values in any of these produce this.","triggerScenarios":"apiBase misconfigured (e.g. missing scheme, containing spaces), or VolumeID/LinkID containing control characters or whitespace from corrupted state, making renameURL unparseable.","commonSituations":"Typo in the driver's apiBase config value; empty or garbage MainShare.VolumeID because Init partially failed; link IDs read from a truncated cache.","solutions":["Log renameURL when this fires and check apiBase config","Validate MainShare.VolumeID is non-empty and looks like a Proton ID after Init","Ensure Init fully completed (RootLink and MainShare populated) before any rename call"],"exampleFix":"// before\nrenameURL := fmt.Sprintf(d.apiBase+\"/drive/v2/volumes/%s/links/%s/rename\", d.MainShare.VolumeID, linkID)\n// after\nif d.MainShare.VolumeID == \"\" || linkID == \"\" { return fmt.Errorf(\"volumeID or linkID is empty\") }\nrenameURL := fmt.Sprintf(d.apiBase+\"/drive/v2/volumes/%s/links/%s/rename\", d.MainShare.VolumeID, linkID)","handlingStrategy":"validation","validationCode":"if d.MainShare == nil || d.MainShare.VolumeID == \"\" {\n    return fmt.Errorf(\"driver not initialized: VolumeID empty\")\n}\nu, err := url.Parse(d.apiBase)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid apiBase: %q\", d.apiBase)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate apiBase and VolumeID once during Init","Never issue driver calls before Init completes"],"tags":["proton-drive","http","url","config"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}