{"record":{"id":"bc425dd4619eb5c3","repo":"grafana/k6","slug":"parsing-k6-exit-on-running-returned-an-error-w","errorCode":null,"errorMessage":"parsing K6_EXIT_ON_RUNNING returned an error: %w","messagePattern":"parsing K6_EXIT_ON_RUNNING returned an error: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":146,"sourceCode":"\t// TODO: refactor (https://github.com/grafana/k6/issues/883)\n\t//\n\t// We deliberately parse the env variables, to validate for wrong\n\t// values, even if we don't subsequently use them (if the respective\n\t// CLI flag was specified, since it has a higher priority).\n\tif showCloudLogsEnv, ok := c.gs.Env[\"K6_SHOW_CLOUD_LOGS\"]; ok {\n\t\tshowCloudLogsValue, err := strconv.ParseBool(showCloudLogsEnv)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"parsing K6_SHOW_CLOUD_LOGS returned an error: %w\", err)\n\t\t}\n\t\tif !cmd.Flags().Changed(\"show-logs\") {\n\t\t\tc.showCloudLogs = showCloudLogsValue\n\t\t}\n\t}\n\n\tif exitOnRunningEnv, ok := c.gs.Env[\"K6_EXIT_ON_RUNNING\"]; ok {\n\t\texitOnRunningValue, err := strconv.ParseBool(exitOnRunningEnv)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"parsing K6_EXIT_ON_RUNNING returned an error: %w\", err)\n\t\t}\n\t\tif !cmd.Flags().Changed(\"exit-on-running\") {\n\t\t\tc.exitOnRunning = exitOnRunningValue\n\t\t}\n\t}\n\treturn nil\n}\n\n// TODO: split apart some more\n//\n//nolint:funlen,gocognit,cyclop\nfunc (c *cmdCloud) run(cmd *cobra.Command, args []string) error {\n\ttest, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// It's important to NOT set the derived options back to the runner","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud.go#L128-L164","documentation":"The `k6 cloud` preRun hook parses K6_EXIT_ON_RUNNING with strconv.ParseBool and fails. As with K6_SHOW_CLOUD_LOGS, only Go-style boolean literals (1/t/true/0/f/false in any capitalization ParseBool accepts) are valid. The value is validated even when --exit-on-running overrides it, so a bad value always stops the command.","triggerScenarios":"K6_EXIT_ON_RUNNING is set to something like 'yes', 'on', '1 ' (trailing space), or 'TRUE\\'', which strconv.ParseBool rejects.","commonSituations":"Templates or CI variables that emit non-literal booleans; copy-pasted env blocks from tutorials using 'on'; secrets managers injecting values with surrounding whitespace.","solutions":["Set K6_EXIT_ON_RUNNING to true or false exactly","Unset the variable if unused","Prefer the --exit-on-running flag, while ensuring any env var present still parses"],"exampleFix":"# before\nexport K6_EXIT_ON_RUNNING=on\n# after\nexport K6_EXIT_ON_RUNNING=true","handlingStrategy":"validation","validationCode":"if v, ok := os.LookupEnv(\"K6_EXIT_ON_RUNNING\"); ok {\n    if _, err := strconv.ParseBool(v); err != nil {\n        log.Fatalf(\"K6_EXIT_ON_RUNNING=%q is not a valid bool (use true/false)\", v)\n    }\n}","typeGuard":"func isValidK6Bool(v string) bool {\n    _, err := strconv.ParseBool(v)\n    return err == nil\n}","tryCatchPattern":null,"preventionTips":["Use only true/false literals in k6 env vars","Normalize boolean env values in CI templates before the k6 step","Document accepted boolean literals for teams used to yes/no style flags"],"tags":["configuration","environment-variables","cli","boolean-parsing"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}