grafana/k6 · error

create or find load test: %w

Error message

create or find load test: %w

What it means

The first step of Client.ProvisionLocalExecution (internal/cloudapi/provisioning/provision.go:59) calls the v6 CreateOrFindLoadTest(projectID, name); this error wraps its failure. The wrapped error comes from v6.CheckResponse: 401/403 for a bad/unauthorized token, 404 for an unknown project, other 4xx/5xx bodies, or a transport error.

Source

Thrown at internal/cloudapi/provisioning/provision.go:59

type ProvisionResult struct {
	// TestRunID is the ID of the provisioned test run.
	TestRunID int64

	// TestRunDetailsPageURL is the URL of the test run details page.
	TestRunDetailsPageURL string

	// RuntimeConfig carries the metrics, secrets, and token
	// configuration returned by the provisioning API.
	RuntimeConfig RuntimeConfig
}

// ProvisionLocalExecution orchestrates the full local-execution
// provisioning flow: CreateOrFindLoadTest → StartLocalExecution →
// optional UploadArchive → WaitForTestRunReady.
func (c *Client) ProvisionLocalExecution(ctx context.Context, params ProvisionParams) (*ProvisionResult, error) {
	loadTestID, err := c.v6Client.CreateOrFindLoadTest(ctx, params.ProjectID, params.Name)
	if err != nil {
		return nil, fmt.Errorf("create or find load test: %w", err)
	}

	// Serialise archive once to get its byte-length for the
	// start_local_execution body. The same buffer is reused for
	// the S3 upload to avoid a second serialisation.
	var (
		archiveSize  int64
		archiveBytes []byte
	)
	if params.Archive != nil {
		var buf bytes.Buffer
		if err := params.Archive.Write(&buf); err != nil {
			return nil, fmt.Errorf("serialising archive: %w", err)
		}
		archiveSize = int64(buf.Len())
		archiveBytes = buf.Bytes()
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Read the wrapped error's status/body — 401/403 vs 404 points to token vs project
  2. Verify the project ID in the Grafana Cloud UI and match it to K6_CLOUD_PROJECT_ID
  3. Confirm the token belongs to the same org/stack as the configured host
  4. Validate the token upfront with v6 Client.ValidateToken to fail fast with a clearer message

Example fix

# before
export K6_CLOUD_PROJECT_ID=123  # stale after migration
k6 run --local-execution script.js

# after
export K6_CLOUD_PROJECT_ID=456  # correct project in current org
k6 run --local-execution script.js
Defensive patterns

Strategy: validation

Validate before calling

if _, err := v6Client.ValidateToken(ctx, stackURL); err != nil {
	return fmt.Errorf("token validation failed; fix credentials before provisioning: %w", err)
}
if params.ProjectID < 1 {
	return errors.New("project ID must be a positive number from the target stack")
}

Type guard

func isAuthOrProjectError(err error) bool {
	var re *cloudapi.ResponseError
	return errors.As(err, &re) && (re.StatusCode == 401 || re.StatusCode == 403 || re.StatusCode == 404)
}

Try / catch

res, err := client.ProvisionLocalExecution(ctx, params)
if err != nil {
	if strings.Contains(err.Error(), "create or find load test") {
		// unwrap for status: 401/403 = token scope, 404 = project ID
	}
	return err
}

Prevention

When it happens

Trigger: Token lacking access to the given projectID; a stale or wrong K6_CLOUD_PROJECT_ID; token issued for a different org than the host/stack; network failure reaching the cloud API.

Common situations: CI with rotated tokens but old project IDs; Grafana Cloud stack migration leaving env vars stale; wrong host (different region/stack) combined with a valid token.

Related errors


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