grafana/k6 · error
invalid stack URL: %w
Error message
invalid stack URL: %w
What it means
v6.Client.ValidateToken (internal/cloudapi/v6/api.go:193) rejects a stack URL that Go's url.Parse cannot parse before sending it as the X-Stack-Url header. url.Parse fails only on grossly malformed input — control characters, invalid bracket/percent syntax — so this error signals a corrupted configuration value, not a merely wrong hostname.
Source
Thrown at internal/cloudapi/v6/api.go:193
zones = append(zones, LoadZone{
ID: zone.Id,
K6LoadZoneID: zone.K6LoadZoneId,
Name: zone.Name,
Public: zone.Public,
Available: zone.Available,
})
}
return zones, nil
}
// ValidateToken validates the cloud authentication token.
func (c *Client) ValidateToken(ctx context.Context, stackURL string) (_ *k6cloud.AuthenticationResponse, err error) {
if stackURL == "" {
return nil, errors.New("stack URL is required to validate token")
}
if _, err := url.Parse(stackURL); err != nil {
return nil, fmt.Errorf("invalid stack URL: %w", err)
}
res, hr, err := c.apiClient.AuthorizationAPI.
Auth(c.authCtx(ctx)).
XStackUrl(stackURL).
Execute()
defer closeResponse(hr, &err)
if err := CheckResponse(hr, err); err != nil {
return nil, err
}
if res == nil {
return nil, errUnknown
}
return res, nil
}
View on GitHub (pinned to 93accf6570)
Solutions
- Print the URL with %q to reveal hidden characters and fix the config source
- Set a clean https://<stack-host> value with no trailing whitespace or newlines
- Validate with url.ParseRequestURI at config-load time to fail with a clearer message
- Prefer explicit flags/env over concatenated values when building the URL
Example fix
# before export K6_CLOUD_HOST="https://my-stack.grafana.net " # trailing space/newline # after export K6_CLOUD_HOST="https://my-stack.grafana.net"
Defensive patterns
Strategy: validation
Validate before calling
u, err := url.ParseRequestURI(stackURL)
if err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("stack URL %q is not a valid absolute URL", stackURL)
} Type guard
func isParsableURL(s string) bool {
_, err := url.Parse(s)
return err == nil
} Try / catch
if _, err := v6Client.ValidateToken(ctx, stackURL); err != nil {
if strings.Contains(err.Error(), "invalid stack URL") {
log.Printf("stack URL %q is malformed; fix the config source", stackURL)
}
return err
} Prevention
- Validate URLs at config load with %q logging to expose hidden characters
- Avoid assembling URLs by string concatenation from templated values
- Set host config as a single clean literal (https://<stack-host>)
When it happens
Trigger: K6_CLOUD_HOST or the passed stackURL containing control characters, a newline from shell quoting, invalid '%' sequences, or malformed IPv6 bracket syntax.
Common situations: Copy-pasting URLs with embedded line breaks; env vars assembled by templating that inject stray characters; config values double-quoted or escaped incorrectly in CI.
Related errors
- invalid stack URL: %w
- 104
- urlTemplate must contain {key} placeholder
- urlTemplate must be an absolute URL with a scheme (e.g., htt
- couldn't parse cloud logs host %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/2212b7b59e6a56d7.
Report an issue: GitHub.