AlistGo/alist · error

failed to create HTTP request: %w

Error message

failed to create HTTP request: %w

What it means

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.

Source

Thrown at drivers/proton_drive/util.go:639

		Size:     srcObj.GetSize(),
		Modified: srcObj.ModTime(),
		IsFolder: srcObj.IsDir(),
	}, nil
}

func (d *ProtonDrive) executeRenameAPI(ctx context.Context, linkID string, req RenameRequest) error {

	renameURL := fmt.Sprintf(d.apiBase+"/drive/v2/volumes/%s/links/%s/rename",
		d.MainShare.VolumeID, linkID)

	reqBody, err := json.Marshal(req)
	if err != nil {
		return fmt.Errorf("failed to marshal rename request: %w", err)
	}

	httpReq, err := http.NewRequestWithContext(ctx, "PUT", renameURL, bytes.NewReader(reqBody))
	if err != nil {
		return fmt.Errorf("failed to create HTTP request: %w", err)
	}

	httpReq.Header.Set("Content-Type", "application/json")
	httpReq.Header.Set("Accept", d.protonJson)
	httpReq.Header.Set("X-Pm-Appversion", d.webDriveAV)
	httpReq.Header.Set("X-Pm-Drive-Sdk-Version", d.sdkVersion)
	httpReq.Header.Set("X-Pm-Uid", d.credentials.UID)
	httpReq.Header.Set("Authorization", "Bearer "+d.credentials.AccessToken)

	client := &http.Client{}
	resp, err := client.Do(httpReq)
	if err != nil {
		return fmt.Errorf("failed to execute rename request: %w", err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("rename failed with status %d", resp.StatusCode)

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Log renameURL when this fires and check apiBase config
  2. Validate MainShare.VolumeID is non-empty and looks like a Proton ID after Init
  3. Ensure Init fully completed (RootLink and MainShare populated) before any rename call

Example fix

// before
renameURL := fmt.Sprintf(d.apiBase+"/drive/v2/volumes/%s/links/%s/rename", d.MainShare.VolumeID, linkID)
// after
if d.MainShare.VolumeID == "" || linkID == "" { return fmt.Errorf("volumeID or linkID is empty") }
renameURL := fmt.Sprintf(d.apiBase+"/drive/v2/volumes/%s/links/%s/rename", d.MainShare.VolumeID, linkID)
Defensive patterns

Strategy: validation

Validate before calling

if d.MainShare == nil || d.MainShare.VolumeID == "" {
    return fmt.Errorf("driver not initialized: VolumeID empty")
}
u, err := url.Parse(d.apiBase)
if err != nil || u.Scheme == "" || u.Host == "" {
    return fmt.Errorf("invalid apiBase: %q", d.apiBase)
}

Prevention

When it happens

Trigger: apiBase misconfigured (e.g. missing scheme, containing spaces), or VolumeID/LinkID containing control characters or whitespace from corrupted state, making renameURL unparseable.

Common situations: Typo in the driver's apiBase config value; empty or garbage MainShare.VolumeID because Init partially failed; link IDs read from a truncated cache.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/e492076f48c0476a. Report an issue: GitHub.