juicedata/juicefs · error

Invalid endpoint %s: %s

Error message

Invalid endpoint %s: %s

What it means

newCOS parses the endpoint with url.ParseRequestURI and wraps any parse failure in this error. The endpoint must be a syntactically valid absolute URL identifying the COS bucket (or be auto-completed with https:// when it lacks a scheme).

Source

Thrown at pkg/object/cos.go:327

	}

	for _, b := range s.Buckets {
		// fmt.Printf("%#v\n", b)
		if b.Name == bucketName {
			return fmt.Sprintf("https://%s.cos.%s.myqcloud.com", b.Name, b.Region), nil
		}
	}

	return "", fmt.Errorf("bucket %q doesn't exist", bucketName)
}

func newCOS(endpoint, accessKey, secretKey, token string) (ObjectStorage, error) {
	if !strings.Contains(endpoint, "://") {
		endpoint = fmt.Sprintf("https://%s", endpoint)
	}
	uri, err := url.ParseRequestURI(endpoint)
	if err != nil {
		return nil, fmt.Errorf("Invalid endpoint %s: %s", endpoint, err)
	}
	hostParts := strings.SplitN(uri.Host, ".", 2)

	if accessKey == "" {
		accessKey = os.Getenv("COS_SECRETID")
		secretKey = os.Getenv("COS_SECRETKEY")
	}

	if len(hostParts) == 1 {
		if endpoint, err = autoCOSEndpoint(hostParts[0], accessKey, secretKey, token); err != nil {
			return nil, fmt.Errorf("Unable to get endpoint of bucket %s: %s", hostParts[0], err)
		}
		if uri, err = url.ParseRequestURI(endpoint); err != nil {
			return nil, fmt.Errorf("Invalid endpoint %s: %s", endpoint, err)
		}
		logger.Debugf("Use endpoint %q", endpoint)
	}

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Fix the endpoint string to a valid absolute URL like https://<bucket>.cos.<region>.myqcloud.com.
  2. URL-encode or remove spaces/invalid characters in the configured endpoint.
  3. Print/log the endpoint value to spot hidden whitespace or truncation before calling newCOS.

Example fix

// before
newCOS("https://my bucket.cos.ap-guangzhou.myqcloud.com", ...)
// after
newCOS("https://mybucket.cos.ap-guangzhou.myqcloud.com", ...)
Defensive patterns

Strategy: validation

Validate before calling

ep := endpoint
if !strings.Contains(ep, "://") {
    ep = "https://" + ep
}
if _, err := url.ParseRequestURI(ep); err != nil {
    return fmt.Errorf("endpoint %q is not a valid URL: %v", endpoint, err)
}

Type guard

func isValidEndpoint(endpoint string) bool {
    if !strings.Contains(endpoint, "://") {
        endpoint = "https://" + endpoint
    }
    _, err := url.ParseRequestURI(endpoint)
    return err == nil
}

Try / catch

obj, err := object.CreateStorage("cos", endpoint, ak, sk, "")
if err != nil && strings.Contains(err.Error(), "Invalid endpoint") {
    return fmt.Errorf("check COS endpoint config: %w", err)
}

Prevention

When it happens

Trigger: Passing an endpoint that fails url.ParseRequestURI even after the https:// prefix is added — e.g. "my bucket", "https://[bad", control characters, or an empty string.

Common situations: Spaces or invalid characters in the endpoint config; unescaped characters; truncated endpoint values from env files; accidentally passing the whole storage URI instead of the endpoint.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/b698bd8b8747b975. Report an issue: GitHub.