{"record":{"id":"0f2c5b0f405791f1","repo":"grafana/k6","slug":"creating-v6-client-w","errorCode":null,"errorMessage":"creating v6 client: %w","messagePattern":"creating v6 client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloudapi/provisioning/client.go","lineNumber":54,"sourceCode":"// NewClient returns a new provisioning Client. It internally constructs\n// both a k6cloud.APIClient (for provisioning endpoints) and a v6.Client\n// (for v6 operations like FetchTest). The stackID identifies the\n// Grafana Cloud stack and is required for the stack-scoped requests.\nfunc NewClient(\n\tlogger logrus.FieldLogger,\n\ttoken, host, version string,\n\tstackID int64,\n\ttimeout time.Duration,\n) (*Client, error) {\n\tif token == \"\" {\n\t\treturn nil, fmt.Errorf(\"token is required to create provisioning API client\")\n\t}\n\n\tcfg := clientcfg.New(host, version, \"k6 Cloud API (provisioning).\", timeout)\n\n\tv6c, err := v6.NewClient(logger, token, host, version, timeout)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating v6 client: %w\", err)\n\t}\n\n\tc := &Client{\n\t\tapiClient: k6cloud.NewAPIClient(cfg),\n\t\tv6Client:  v6c,\n\t\ttoken:     token,\n\t\tstackID:   stackID,\n\t\thost:      host,\n\t\tversion:   version,\n\t\tlogger:    logger,\n\t}\n\t// Propagate the stack ID to the embedded v6 client. v6.SetStackID\n\t// validates that it fits the int32 the SDK's X-Stack-Id requires —\n\t// that is the single place the int32 boundary is enforced.\n\tif err := c.v6Client.SetStackID(stackID); err != nil {\n\t\treturn nil, err\n\t}\n\t// The provisioning endpoints carry the stack ID as a decimal-string","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/cloudapi/provisioning/client.go#L36-L72","documentation":"Returned by provisioning.NewClient (internal/cloudapi/provisioning/client.go:54) when the embedded v6.NewClient call fails. Reading internal/cloudapi/v6/client.go:29-32, the v6 constructor's only failure mode is an empty token — but provisioning.NewClient has already rejected empty tokens at client.go:47 before this call, so with current code this error is effectively unreachable. Seeing it in the wild implies version drift (the two checks disagree) or a patched/derived build.","triggerScenarios":"v6.NewClient returning an error, which per its source happens only for token == \"\"; reachable only if the empty-token guard above was removed/altered or the embedded v6 package's failure modes changed between versions.","commonSituations":"Mixing k6 versions via replace directives or vendored forks where client.go and v6/client.go diverge; downstream forks adding new validation to v6.NewClient without updating provisioning.","solutions":["Confirm you are running a consistent k6 build (no partial vendoring/replace directives mixing versions) — 'go version -m ./k6' or rebuild from clean checkout.","If you maintain a fork that added new failure modes to v6.NewClient, either handle them here or keep the token guard and v6 contract in sync.","For upstream builds, treat occurrence as a bug: report the k6 version and stack trace to the k6 issue tracker."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Guard the inputs this wrapper is known to need, since its own failure is defensive-only.\nif token == \"\" {\n\treturn errors.New(\"empty cloud token\")\n}\nif _, err := v6.NewClient(logger, token, host, version, timeout); err != nil {\n\treturn fmt.Errorf(\"v6 client rejected configuration: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := provisioning.NewClient(logger, token, host, version, stackID, timeout); err != nil {\n\tif strings.Contains(err.Error(), \"creating v6 client\") {\n\t\t// effectively unreachable upstream — indicates version drift or a fork; realign versions\n\t\treturn fmt.Errorf(\"k6 build inconsistency (provisioning vs v6 client contract): %w\", err)\n\t}\n}","preventionTips":["Build k6 from a single consistent version; avoid mixing vendored/replace directives across internal/cloudapi packages.","If forking, keep provisioning.NewClient's guards and v6.NewClient's failure modes in sync.","Report upstream occurrences with the exact k6 version."],"tags":["k6","cloud","provisioning","client-init","unreachable-code","version-skew"],"backgroundTag":"client-initialization-failed","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}