{"record":{"id":"34c0d9feb9b03144","repo":"argoproj/argo-workflows","slug":"workflow-cannot-be-nil","errorCode":null,"errorMessage":"workflow cannot be nil","messagePattern":"workflow cannot be nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/util/util.go","lineNumber":249,"sourceCode":"func PopulateSubmitOpts(command *cobra.Command, submitOpts *wfv1.SubmitOpts, parameterFile *string, includeDryRun bool) {\n\tcommand.Flags().StringVar(&submitOpts.Name, \"name\", \"\", \"override metadata.name\")\n\tcommand.Flags().StringVar(&submitOpts.GenerateName, \"generate-name\", \"\", \"override metadata.generateName\")\n\tcommand.Flags().StringVar(&submitOpts.Entrypoint, \"entrypoint\", \"\", \"override entrypoint\")\n\tcommand.Flags().StringArrayVarP(&submitOpts.Parameters, \"parameter\", \"p\", []string{}, \"pass an input parameter\")\n\tcommand.Flags().StringVar(&submitOpts.ServiceAccount, \"serviceaccount\", \"\", \"run all pods in the workflow using specified serviceaccount\")\n\tcommand.Flags().StringVarP(parameterFile, \"parameter-file\", \"f\", \"\", \"pass a file containing all input parameters\")\n\tcommand.Flags().StringVarP(&submitOpts.Labels, \"labels\", \"l\", \"\", \"Comma separated labels to apply to the workflow. Will override previous values.\")\n\n\tif includeDryRun {\n\t\tcommand.Flags().BoolVar(&submitOpts.DryRun, \"dry-run\", false, \"modify the workflow on the client-side without creating it\")\n\t\tcommand.Flags().BoolVar(&submitOpts.ServerDryRun, \"server-dry-run\", false, \"send request to server with dry-run flag which will modify the workflow without creating it\")\n\t}\n}\n\n// ApplySubmitOpts applies the submit options to a workflow object.\nfunc ApplySubmitOpts(wf *wfv1.Workflow, opts *wfv1.SubmitOpts) error {\n\tif wf == nil {\n\t\treturn fmt.Errorf(\"workflow cannot be nil\")\n\t}\n\tif opts == nil {\n\t\topts = &wfv1.SubmitOpts{}\n\t}\n\tif opts.Entrypoint != \"\" {\n\t\twf.Spec.Entrypoint = opts.Entrypoint\n\t}\n\tif opts.ServiceAccount != \"\" {\n\t\twf.Spec.ServiceAccountName = opts.ServiceAccount\n\t}\n\tif opts.PodPriorityClassName != \"\" {\n\t\twf.Spec.PodPriorityClassName = opts.PodPriorityClassName\n\t}\n\n\tif opts.Priority != nil {\n\t\twf.Spec.Priority = opts.Priority\n\t}\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/util/util.go#L231-L267","documentation":"ApplySubmitOpts mutates a *wfv1.Workflow with CLI/server submit options; it requires a non-nil workflow pointer. A nil wf is a programming error by the caller (the workflow was never formulated/loaded), so it fails fast with this error rather than panicking.","triggerScenarios":"Calling ApplySubmitOpts(nil, opts) directly, or passing a workflow that a prior formulate/parse step failed to produce (caller ignored an earlier error and passed a nil *wfv1.Workflow) from CreateCronWorkflows, updateCronWorkflows, submitWorkflows, or SubmitWorkflow.","commonSituations":"Custom tooling built on workflow/util that skips workflow formulation; error from unmarshal/FromFile ignored so wf stays nil; refactoring that reordered code so ApplySubmitOpts runs before the wf is created.","solutions":["Ensure the workflow is successfully created/parsed before calling ApplySubmitOpts and propagate earlier errors","Add a nil check on the result of the formulate/parse step before applying submit options","If using CLI, verify the file/URL/- arguments actually produce a workflow (argo submit with valid input)"],"exampleFix":"// before\nwf, err := util.FromFile(...) // err ignored\n_ = util.ApplySubmitOpts(wf, opts) // wf is nil\n// after\nwf, err := util.FromFile(...)\nif err != nil { return err }\nif err := util.ApplySubmitOpts(wf, opts); err != nil { return err }","handlingStrategy":"type-guard","validationCode":"if wf == nil {\n    return fmt.Errorf(\"cannot submit: workflow is nil, check formulate/parse step\")\n}","typeGuard":"func workflowReady(wf *wfv1.Workflow) bool {\n    return wf != nil && wf.Spec.Entrypoint != \"\"\n}","tryCatchPattern":"if err := util.ApplySubmitOpts(wf, opts); err != nil {\n    if strings.Contains(err.Error(), \"workflow cannot be nil\") {\n        return fmt.Errorf(\"bug: workflow not constructed before ApplySubmitOpts: %w\", err)\n    }\n    return err\n}","preventionTips":["Always check errors from workflow formulation before applying submit opts","Wrap submit pipelines so nil workflows cannot reach ApplySubmitOpts","Add unit tests covering the full formulate -> ApplySubmitOpts path"],"tags":["nil-check","submit","validation"],"backgroundTag":"nil-workflow-object","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}