grafana/k6 · error

invalid stack URL

Error message

invalid stack URL: %w

What it means

resolveCloudTestURL could not parse the configured stack URL while building the test details link (…/a/k6-app/tests/<id>) shown after a cloud upload/run. url.Parse only errors on fundamentally malformed strings (control characters, bad percent-escapes), so the stack URL stored in cloudConfig.StackURL.String is corrupt even though the API calls themselves may have succeeded via a different host setting.

Solutions

  1. Re-run `k6 cloud login` to rewrite a clean stack URL
  2. Inspect the stored value (print with %q) and strip quotes, whitespace, and control characters
  3. Validate K6_CLOUD_STACK_URL in your provisioning scripts before injecting it into k6 config

Example fix

// before
u, err := url.Parse(stackURL)
if err != nil { return "", fmt.Errorf("invalid stack URL: %w", err) }

// after
stackURL = strings.TrimSpace(strings.Trim(stackURL, "\"'"))
u, err := url.Parse(stackURL)
if err != nil || u.Scheme == "" || u.Host == "" {
    return "", fmt.Errorf("stack URL %q must be a full https URL", stackURL)
}
Defensive patterns

Strategy: validation

Validate before calling

func normalizeStackURL(raw string) (string, error) {
    raw = strings.TrimSpace(strings.Trim(raw, "\"'"))
    u, err := url.Parse(raw)
    if err != nil || u.Scheme == "" || u.Host == "" {
        return "", fmt.Errorf("stack URL %q is not a full https URL", raw)
    }
    return u.String(), nil
}

Prevention

When it happens

Trigger: StackURL copied from config or env containing a newline/control character, invalid %-sequence like %zz, or a value like '\"https://x\"' with literal quotes surviving into the config file.

Common situations: Hand-edited or templated config files (Helm values, dotenv) introducing quotes/escapes, CI secrets with trailing newlines, or Windows CRLF artifacts in the login config.

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 grafana/k6@94169daab2 (2026-08-18). Data as JSON: /api/errors/92a0962b0f2ea434. Report an issue: GitHub.

Appendix: source

Thrown at internal/cmd/cloud.go:614

	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 94169daab2)