{"record":{"id":"3db6b9e78252cbbf","repo":"grafana/k6","slug":"could-not-load-and-configure-the-test-w","errorCode":null,"errorMessage":"could not load and configure the test: %w","messagePattern":"could not load and configure the test: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud_run.go","lineNumber":153,"sourceCode":"\t\t)\n\t}\n\n\tif c.noCloudLogs {\n\t\treturn errext.WithExitCodeIfNone(\n\t\t\tfmt.Errorf(\"the --no-cloud-logs flag can only be used in conjunction with the --local-execution flag\"),\n\t\t\texitcodes.InvalidConfig,\n\t\t)\n\t}\n\n\treturn c.deprecatedCloudCmd.preRun(cmd, args)\n}\n\nfunc (c *cmdCloudRun) run(cmd *cobra.Command, args []string) error {\n\tif c.localExecution {\n\t\tc.runCmd.loadConfiguredTest = func(*cobra.Command, []string) (*loadedAndConfiguredTest, execution.Controller, error) {\n\t\t\ttest, err := loadAndConfigureLocalTest(c.runCmd.gs, cmd, args, getCloudRunLocalExecutionConfig)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"could not load and configure the test: %w\", err)\n\t\t\t}\n\n\t\t\tif err := createCloudTest(c.runCmd.gs, test); err != nil {\n\t\t\t\tif errors.Is(err, errCloudAuth) {\n\t\t\t\t\treturn nil, nil, err\n\t\t\t\t}\n\t\t\t\treturn nil, nil, fmt.Errorf(\"could not create the cloud test run: %w\", err)\n\t\t\t}\n\n\t\t\treturn test, local.NewController(), nil\n\t\t}\n\t\treturn c.runCmd.run(cmd, args)\n\t}\n\n\t// When running the `k6 cloud run` command explicitly disable the usage report.\n\tc.noUsageReport = true\n\n\treturn c.deprecatedCloudCmd.run(cmd, args)","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud_run.go#L135-L171","documentation":"In the --local-execution path of `k6 cloud run`, the test is loaded and configured by loadAndConfigureLocalTest (using getCloudRunLocalExecutionConfig); any failure is wrapped with this message. The wrapped cause is the ordinary test-loading pipeline, so it ranges from file and syntax errors to invalid options, bad env-var config, or a missing default export.","triggerScenarios":"Running `k6 cloud run --local-execution script.js` where the file does not exist, contains a JavaScript syntax or import error, exports no default function, has invalid options (scenarios, thresholds), or where a K6_* env var / --config file fails validation.","commonSituations":"Path typos or wrong working directory in CI; a script that runs under `k6 run` on an older k6 but uses options the newer cloud-run config rejects; env vars like K6_CLOUD_TIMEOUT set to non-durations; broken imports after dependency changes.","solutions":["Run `k6 run script.js` (or `k6 inspect script.js`) locally to surface the exact underlying error","Fix the reported script issue: path, syntax, imports, missing default export","Validate options and any --config file / K6_* env overrides named in the wrapped error"],"exampleFix":"// before: script.js exports nothing\nconst http = require('k6/http')\n// after\nconst http = require('k6/http')\nexport default function () { http.get('https://test.k6.io') }","handlingStrategy":"validation","validationCode":"// pre-flight: the script must at least load\nif err := exec.Command(\"k6\", \"inspect\", \"script.js\").Run(); err != nil {\n    log.Fatalf(\"script.js does not load: %v\", err)\n}\n// then: k6 cloud run --local-execution script.js","typeGuard":null,"tryCatchPattern":"test, err := loadAndConfigureLocalTest(gs, cmd, args, getCloudRunLocalExecutionConfig)\nif err != nil {\n    return fmt.Errorf(\"could not load and configure the test: %w\", err)\n    // unwrap with errors.Unwrap in callers to distinguish file vs options vs env errors\n}","preventionTips":["Run `k6 inspect script.js` (or `k6 run`) in CI before the cloud step to catch load errors cheaply","Keep scripts self-contained: valid imports, a default export, and no machine-specific paths","Validate --config files and K6_* env overrides in a lint step for the pipeline"],"tags":["script","configuration","cloud-run","javascript","local-execution"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}