AlistGo/alist · error

invalid URL format: %w

Error message

invalid URL format: %w

What it means

signRequest parses the upload URL (uploadUrl) with url.Parse before building the Volcengine-style V4 signature for the upload host. If parsing fails the operation aborts before signing. In practice url.Parse almost never fails on absolute URLs, so this error usually signals a corrupted upload URL received from the upload-config endpoint (control characters, empty string edge cases, or malformed host from server config).

Source

Thrown at drivers/doubao/util.go:157

	return resp, err
}

func (d *Doubao) getUserInfo() (UserInfo, error) {
	var r UserInfoResp

	_, err := d.request("/passport/account/info/v2/", http.MethodGet, nil, &r)
	if err != nil {
		return UserInfo{}, err
	}

	return r.Data, err
}

// 签名请求
func (d *Doubao) signRequest(req *resty.Request, method, tokenType, uploadUrl string) error {
	parsedUrl, err := url.Parse(uploadUrl)
	if err != nil {
		return fmt.Errorf("invalid URL format: %w", err)
	}

	var accessKeyId, secretAccessKey, sessionToken string
	var serviceName string

	if tokenType == VideoDataType {
		accessKeyId = d.UploadToken.Samantha.StsToken.AccessKeyID
		secretAccessKey = d.UploadToken.Samantha.StsToken.SecretAccessKey
		sessionToken = d.UploadToken.Samantha.StsToken.SessionToken
		serviceName = "vod"
	} else {
		accessKeyId = d.UploadToken.Alice[tokenType].Auth.AccessKeyID
		secretAccessKey = d.UploadToken.Alice[tokenType].Auth.SecretAccessKey
		sessionToken = d.UploadToken.Alice[tokenType].Auth.SessionToken
		serviceName = "imagex"
	}

	// 当前时间,格式为 ISO8601

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Log the uploadUrl value when this fires — the parse error text pinpoints the offending characters
  2. If the URL is empty or truncated, the upload token/config fetch above it is the real failure; refresh the upload token (initUploadToken) and retry
  3. Report upstream if the provider consistently returns hosts that fail standard URL parsing

Example fix

// before
parsedUrl, err := url.Parse(uploadUrl)
if err != nil {
	return fmt.Errorf("invalid URL format: %w", err)
}
// after
parsedUrl, err := url.Parse(uploadUrl)
if err != nil {
	return fmt.Errorf("invalid upload URL %q: %w", uploadUrl, err)
}
Defensive patterns

Strategy: validation

Validate before calling

parsed, err := url.Parse(uploadUrl)
if err != nil || parsed.Scheme == "" || parsed.Host == "" {
	return fmt.Errorf("upload URL %q is not absolute and parseable", uploadUrl)
}

Type guard

func isUsableUploadURL(u string) bool {
	p, err := url.Parse(u)
	return err == nil && (p.Scheme == "http" || p.Scheme == "https") && p.Host != ""
}

Try / catch

if strings.Contains(err.Error(), "invalid URL format") {
	// upstream config is corrupt: refresh upload token/config and retry once
}

Prevention

When it happens

Trigger: uploadUrl built from uploadNode.UploadHost + storeInfo.StoreURI contains characters url.Parse rejects (control chars, spaces in odd places), or the config endpoint returned empty/garbage host fields that produced an unparseable URL string.

Common situations: Doubao backend returning unexpected upload host values after an app update; a token type (Alice vs Samantha) mapping to missing keys, producing malformed URL construction upstream; proxy or middleware mangling the URL string.

Related errors


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