{"record":{"id":"205056844ec58a6b","repo":"argoproj/argo-workflows","slug":"failed-to-parse-yaml-from-file-s-w","errorCode":null,"errorMessage":"failed to parse YAML from file %s: %w","messagePattern":"failed to parse YAML from file (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiclient/offline-client.go","lineNumber":55,"sourceCode":"}\n\nvar ErrOffline = fmt.Errorf(\"not supported when you are in offline mode\")\n\nvar _ Client = &offlineClient{}\n\n// newOfflineClient creates a client that keeps all files (or files recursively contained within a path) given to it in memory.\n// It is useful for linting a set of files without having to connect to a cluster.\nfunc newOfflineClient(ctx context.Context, paths []string) (context.Context, Client, error) {\n\tclusterWorkflowTemplateGetter := &offlineClusterWorkflowTemplateGetter{\n\t\tclusterWorkflowTemplates: map[string]*wfv1.ClusterWorkflowTemplate{},\n\t}\n\tworkflowTemplateGetters := offlineWorkflowTemplateGetterMap{}\n\tfor _, basePath := range paths {\n\t\terr := file.WalkManifests(ctx, basePath, func(path string, bytes []byte) error {\n\t\t\tfor _, pr := range common.ParseObjects(ctx, bytes, false) {\n\t\t\t\tobj, err := pr.Object, pr.Err\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to parse YAML from file %s: %w\", path, err)\n\t\t\t\t}\n\n\t\t\t\tif obj == nil {\n\t\t\t\t\tcontinue // could not parse to kubernetes object\n\t\t\t\t}\n\n\t\t\t\tobjName := obj.GetName()\n\t\t\t\tnamespace := obj.GetNamespace()\n\n\t\t\t\tswitch v := obj.(type) {\n\t\t\t\tcase *wfv1.ClusterWorkflowTemplate:\n\t\t\t\t\tif _, ok := clusterWorkflowTemplateGetter.clusterWorkflowTemplates[objName]; ok {\n\t\t\t\t\t\treturn fmt.Errorf(\"duplicate ClusterWorkflowTemplate found: %q\", objName)\n\t\t\t\t\t}\n\t\t\t\t\tclusterWorkflowTemplateGetter.clusterWorkflowTemplates[objName] = v\n\n\t\t\t\tcase *wfv1.WorkflowTemplate:\n\t\t\t\t\tgetter, ok := workflowTemplateGetters[namespace]","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/pkg/apiclient/offline-client.go#L37-L73","documentation":"When building the in-memory template store for the offline client, argo walks the given paths and parses every YAML/JSON manifest. If any document fails to parse into a Kubernetes object, the walk is aborted and this wrapped error (with the offending file path) is returned from newOfflineClient.","triggerScenarios":"Running `argo lint` / creating an offline client over a path containing a file whose YAML is malformed, has bad indentation, or contains a document that common.ParseObjects cannot parse into a k8s object (pr.Err non-nil).","commonSituations":"Hand-edited manifest with a YAML typo; a file with mixed tabs/spaces; multi-doc file where one document is broken; passing a directory that includes generated or partial files that are not valid manifests.","solutions":["Open the file named in the message and fix the YAML syntax error reported by the wrapped parse error.","Run `yamllint` or a YAML parser on the file to pinpoint the broken document.","Split multi-document files and validate each document individually to find the failing one."],"exampleFix":"// before (broken YAML)\nmetadata:\n  name: tmpl\n spec:\n   templates: []\n// after\nmetadata:\n  name: tmpl\nspec:\n  templates: []","handlingStrategy":"validation","validationCode":"import \"sigs.k8s.io/yaml\"\nfunc validateYAMLFile(path string) error {\n    b, err := os.ReadFile(path)\n    if err != nil { return err }\n    var out []map[string]any\n    return yaml.Unmarshal(b, &out)\n}","typeGuard":null,"tryCatchPattern":"client, err := apiclient.NewOfflineClient(ctx, paths)\nif err != nil {\n    var pathErr *fs.PathError\n    if strings.Contains(err.Error(), \"failed to parse YAML from file\") {\n        // surface err to the user: fix the YAML in the named file\n    }\n    return err\n}","preventionTips":["Run yamllint / a schema validator over manifests before linting.","Validate each document of multi-doc files separately during authoring.","Lint files in CI so broken YAML is caught before submission."],"tags":["go","yaml","parsing","offline-mode"],"backgroundTag":"yaml-parse-failed","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"}