{"record":{"id":"1a3fc4af370836fe","repo":"GoogleContainerTools/skaffold","slug":"skaffold-cmdline-is-invalid-w","errorCode":null,"errorMessage":"SKAFFOLD_CMDLINE is invalid: %w","messagePattern":"SKAFFOLD_CMDLINE is invalid: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/skaffold/app/skaffold.go","lineNumber":45,"sourceCode":"\n\tshell \"github.com/kballard/go-shellquote\"\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/cmd/skaffold/app/cmd\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log\"\n)\n\nfunc Run(out, stderr io.Writer) error {\n\tctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGINT, syscall.SIGPIPE)\n\tdefer cancel()\n\n\tcatchStackdumpRequests()\n\n\tc := cmd.NewSkaffoldCommand(out, stderr)\n\tif cmdLine := os.Getenv(\"SKAFFOLD_CMDLINE\"); cmdLine != \"\" && len(os.Args) == 1 {\n\t\tparsed, err := shell.Split(cmdLine)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"SKAFFOLD_CMDLINE is invalid: %w\", err)\n\t\t}\n\t\t// XXX logged before logrus.SetLevel is called in NewSkaffoldCommand's PersistentPreRunE\n\t\tlog.Entry(ctx).Debugf(\"Retrieving command line from SKAFFOLD_CMDLINE: %q\", parsed)\n\t\tc.SetArgs(parsed)\n\t}\n\tc, err := c.ExecuteContextC(ctx)\n\tif err != nil {\n\t\terr = extractInvalidUsageError(err)\n\t\tif errors.Is(err, context.Canceled) {\n\t\t\tlog.Entry(ctx).Debugln(\"ignore error since context is cancelled:\", err)\n\t\t} else if !cmd.ShouldSuppressErrorReporting(c) {\n\t\t\t// As we allow some color setup using CLI flags for the main run, we can't run SetupColors()\n\t\t\t// for the entire skaffold run here. It's possible SetupColors() was never called, so call it again\n\t\t\t// before we print an error to get the right coloring.\n\t\t\terrOut := output.SetupColors(context.Background(), stderr, output.DefaultColorCode, false)\n\t\t\toutput.Red.Fprintln(errOut, err)\n\t\t}\n\t}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/cmd/skaffold/app/skaffold.go#L27-L63","documentation":"When skaffold is invoked with no CLI args (len(os.Args)==1) and the SKAFFOLD_CMDLINE env var is set (used by phases like deploy/build to propagate the original command line to a re-executed binary), Run() attempts to shell-split that value. If shell.Split fails (unbalanced quotes, malformed escaping), the error is wrapped as `SKAFFOLD_CMDLINE is invalid`.","triggerScenarios":"Invoking the skaffold binary with zero arguments while SKAFFOLD_CMDLINE contains a string shell.Split cannot parse — e.g. dangling quote `skaffold run --tag \"`, unbalanced parentheses, or manual export of a corrupted value.","commonSituations":"Manually exporting SKAFFOLD_CMDLINE in a shell/CI to test behavior; a parent skaffold process serializing a command line containing characters shell.Split rejects; wrapper scripts clobbering the env var.","solutions":["Unset SKAFFOLD_CMDLINE (`unset SKAFFOLD_CMDLINE`) when invoking skaffold manually.","Fix quoting in the value so it parses as shell tokens (balanced quotes/escapes).","Run skaffold with explicit arguments instead of relying on the env var (len(os.Args)>1 skips this path)."],"exampleFix":"// before\nexport SKAFFOLD_CMDLINE='run --profile \"dev'; skaffold\n// after\nunset SKAFFOLD_CMDLINE; skaffold run --profile dev","handlingStrategy":"try-catch","validationCode":"if v, ok := os.LookupEnv(\"SKAFFOLD_CMDLINE\"); ok && v != \"\" {\n    if _, err := shell.Split(v); err != nil {\n        os.Unsetenv(\"SKAFFOLD_CMDLINE\")\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := runSkaffold(); err != nil {\n    if strings.Contains(err.Error(), \"SKAFFOLD_CMDLINE is invalid\") {\n        os.Unsetenv(\"SKAFFOLD_CMDLINE\")\n        err = runSkaffold()\n    }\n}","preventionTips":["Unset SKAFFOLD_CMDLINE when invoking skaffold interactively or in CI wrappers.","Never hand-write the env var; let skaffold set it.","Always pass explicit CLI arguments so the env-var path is skipped."],"tags":["environment-variable","shell-parsing","skaffold"],"backgroundTag":"invalid-env-var","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}