{"record":{"id":"70580944802e19f3","repo":"mikefarah/yq","slug":"could-not-load-s","errorCode":null,"errorMessage":"could not load %s","messagePattern":"could not load (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_load.go","lineNumber":35,"sourceCode":"type loadPrefs struct {\n\tdecoder Decoder\n}\n\nfunc loadString(filename string) (*CandidateNode, error) {\n\t// ignore CWE-22 gosec issue - that's more targeted for http based apps that run in a public directory,\n\t// and ensuring that it's not possible to give a path to a file outside that directory.\n\n\tfilebytes, err := os.ReadFile(filename) // #nosec\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &CandidateNode{Kind: ScalarNode, Tag: \"!!str\", Value: string(filebytes)}, nil\n}\n\nfunc loadWithDecoder(filename string, decoder Decoder) (*CandidateNode, error) {\n\tif decoder == nil {\n\t\treturn nil, fmt.Errorf(\"could not load %s\", filename)\n\t}\n\n\tfile, err := os.Open(filename) // #nosec\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treader := bufio.NewReader(file)\n\n\tdocuments, err := readDocuments(reader, filename, 0, decoder)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif documents.Len() == 0 {\n\t\t// return null candidate\n\t\treturn &CandidateNode{Kind: ScalarNode, Tag: \"!!null\"}, nil\n\t} else if documents.Len() == 1 {\n\t\tcandidate := documents.Front().Value.(*CandidateNode)","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_load.go#L17-L53","documentation":"The `load` operators (load, load_yaml, load_json, etc.) resolve a file path at evaluation time. loadWithDecoder first checks that a decoder factory exists for the requested format; if none is registered (e.g. a stripped yq build compiled without that format via build tags), it cannot proceed and reports 'could not load <file>'. This surfaces as a load failure even though the file may exist.","triggerScenarios":"Using `load_xml(\"f.xml\")` (or another format-specific loader) with a yq binary compiled without that format (yq_noxml-style build tags), so the decoder factory returns nil.","commonSituations":"Minimal/small yq distributions (tinygo, stripped builds) missing optional formats; mixing up operator names so an unavailable loader is invoked; custom builds where format registration was omitted.","solutions":["Use a full yq build that includes the needed format decoder","Check the binary's supported formats (yq --help) and pick the matching load operator","Pre-convert the file with a tool that supports the format, then load it as yaml/json","If building yq yourself, remove the yq_no<format> build tag for the required format"],"exampleFix":"// before (yq built with -tags yq_noxml)\nyq '.a = load_xml(\"data.xml\")' doc.yaml\n// error: could not load data.xml\n\n// after: use a full build, or load a supported format\nyq '.a = load(\"data.yaml\")' doc.yaml","handlingStrategy":"fallback","validationCode":"test -f data.xml && yq --help | grep -q xml && echo \"format supported\"","typeGuard":null,"tryCatchPattern":"out=$(yq '.a = load_xml(\"data.xml\")' doc.yaml 2>&1) || {\n  echo \"load failed (decoder unavailable or file missing): $out\" >&2\n  exit 1\n}","preventionTips":["Pin the full yq distribution in CI images","Verify the binary supports the format before using load_<format>","Check file existence with test -f before load expressions","Convert exotic formats to yaml/json upstream"],"tags":["yq","load","build-tags","decoder"],"backgroundTag":"format-decoder-unavailable","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}