grafana/k6 · error

invalid url %q

Error message

invalid url %q

What it means

Intended to reject an unparseable url= value in K6_BROWSER_SCREENSHOTS_OUTPUT (file_persister.go:83), but the guard is defective: url.ParseRequestURI returns a nil *url.URL on error, so the condition 'err != nil && u.Scheme != "" && u.Host != ""' never evaluates cleanly when parsing fails. In practice this exact error is nearly unreachable; bad URLs slip through unvalidated and fail later (or crash) at upload time.

Source

Thrown at internal/js/modules/k6/browser/browser/file_persister.go:83

			hh := strings.Split(k, ".")
			if len(hh) != 2 {
				return presignedURLConfig{}, fmt.Errorf("format of header must be header.k=v, received %q", s)
			}

			k = hh[0]
			hk = hh[1]

			if hk == "" {
				return presignedURLConfig{}, fmt.Errorf("empty header key, received %q", s)
			}
		}

		switch k {
		case "url":
			u, err := url.ParseRequestURI(v)
			if err != nil && u.Scheme != "" && u.Host != "" {
				return presignedURLConfig{}, fmt.Errorf("invalid url %q", s)
			}
			presignedURL.getterURL = v
		case "basePath":
			presignedURL.basePath = v
		case "header":
			presignedURL.headers[hk] = hv
		default:
			return presignedURLConfig{}, fmt.Errorf("invalid option %q", k)
		}
	}

	if presignedURL.getterURL == "" {
		return presignedURLConfig{}, errors.New("missing required url")
	}

	return presignedURL, nil
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Always set url= to a fully-qualified absolute URL with scheme and host: url=https://uploads.example.com/
  2. Verify it parses and responds before the test: curl -fsSI "$URL" >/dev/null && echo ok
  3. Add a pre-flight check in Go: if _, err := url.ParseRequestURI(v); err != nil { return err }
  4. If you can reproduce this exact message or a nil-pointer panic near it, report the defect to k6 (the guard dereferences a nil URL)

Example fix

# before
K6_BROWSER_SCREENSHOTS_OUTPUT="url=uploads.example.com/,basePath=/s"
# after
K6_BROWSER_SCREENSHOTS_OUTPUT="url=https://uploads.example.com/,basePath=/s"
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
u="${K6_BROWSER_SCREENSHOTS_OUTPUT#url=}"; u="${u%%,*}"
case "$u" in
  https://*/*|http://*/*) : ;;
  *) echo "url= must be an absolute http(s) URL ending with /, got: $u" >&2; exit 1 ;;
esac
curl -fsSI --max-time 5 "$u" >/dev/null || { echo "upload URL not reachable: $u" >&2; exit 1; }

Prevention

When it happens

Trigger: Setting url= to something that is not an absolute request URI, e.g. 'url=notaurl' or 'url=/relative/path'. Because of the broken condition the error usually does not fire; the failure surfaces later when the remote persister tries to PUT the screenshot to an unusable URL.

Common situations: Forgetting the scheme ('url=example.com/uploads'), using a relative path, or a typo'd hostname; the resulting symptom is a confusing downstream upload error instead of this clean message.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/d3e99ccaf54fa074. Report an issue: GitHub.