grafana/k6 · error
invalid stack URL: %w
Error message
invalid stack URL: %w
What it means
resolveCloudTestURL parses the configured stack URL with url.Parse before joining the test path; if parsing fails this error wraps the url package's parse error. url.Parse almost never fails — only malformed input such as control characters, a bad percent-encoding (e.g. '%zz'), or an invalid port triggers it. The stack URL comes from the login config or K6_CLOUD_STACK_URL.
Source
Thrown at internal/cmd/cloud.go:592
if projectID > 0 {
tmpCloudConfig["projectID"] = projectID
b, err := json.Marshal(tmpCloudConfig)
if err != nil {
return err
}
arc.Options.Cloud = b
cloudConfig.ProjectID = null.IntFrom(projectID)
}
return nil
}
func resolveCloudTestURL(stackURL string, testID int64) (string, error) {
u, err := url.Parse(stackURL)
if err != nil {
return "", fmt.Errorf("invalid stack URL: %w", err)
}
return u.JoinPath("a", "k6-app", "tests", strconv.FormatInt(testID, 10)).String(), nil
}
View on GitHub (pinned to 93accf6570)
Solutions
- Re-run `k6 cloud login` to store a clean, canonical stack URL
- Fix or unset K6_CLOUD_STACK_URL; it must be a plain absolute URL like https://team.grafana.net
- Strip whitespace/newlines from CI-injected URL variables
Example fix
# before export K6_CLOUD_STACK_URL=$'https://team.grafana.net\r' # after export K6_CLOUD_STACK_URL=https://team.grafana.net
Defensive patterns
Strategy: validation
Validate before calling
if raw, ok := os.LookupEnv("K6_CLOUD_STACK_URL"); ok {
trimmed := strings.TrimSpace(raw)
u, err := url.Parse(trimmed)
if err != nil || u.Scheme == "" || u.Host == "" {
log.Fatalf("K6_CLOUD_STACK_URL=%q is not an absolute URL", raw)
}
} Type guard
func isValidStackURL(raw string) bool {
u, err := url.Parse(strings.TrimSpace(raw))
return err == nil && u.Scheme != "" && u.Host != ""
} Prevention
- Trim whitespace/newlines from CI-injected URLs
- Prefer `k6 cloud login` to store the canonical stack URL
- Never assemble stack URLs by string concatenation with unvalidated parts
When it happens
Trigger: The stored stack URL or K6_CLOUD_STACK_URL contains control characters, invalid escape sequences, or a malformed port (e.g. 'https://team.grafana.net:80x' or a value copied with an embedded newline).
Common situations: Hand-edited config.json; CI variables injected with a trailing newline or carriage return; stack URLs assembled by string concatenation with unescaped characters.
Related errors
- couldn't parse cloud logs host %w
- creating upload request: %w
- invalid stack URL: %w
- stack URL is required to validate token
- Run `k6 cloud login` to authenticate, or check the docs for
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/92a0962b0f2ea434.
Report an issue: GitHub.