{"id":"f4c9712b0ae98d8b","repo":"stretchr/testify","slug":"yaml-functions-are-not-available-see-https-pkg","errorCode":null,"errorMessage":"YAML functions are not available (see https://pkg.go.dev/github.com/stretchr/testify/assert/yaml)","messagePattern":"YAML functions are not available \\(see https://pkg\\.go\\.dev/github\\.com/stretchr/testify/assert/yaml\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"info","filePath":"assert/yaml/yaml_fail.go","lineNumber":13,"sourceCode":"//go:build testify_yaml_fail && !testify_yaml_custom && !testify_yaml_default\n\n// Package yaml is an implementation of YAML functions that always fail.\n//\n// This implementation can be used at build time to replace the default implementation\n// to avoid linking with [gopkg.in/yaml.v3]:\n//\n//\tgo test -tags testify_yaml_fail\npackage yaml\n\nimport \"errors\"\n\nvar errNotImplemented = errors.New(\"YAML functions are not available (see https://pkg.go.dev/github.com/stretchr/testify/assert/yaml)\")\n\nfunc Unmarshal([]byte, interface{}) error {\n\treturn errNotImplemented\n}\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/stretchr/testify/blob/001eb7946baf451879253643e4ce4b38eaa0d4a7/assert/yaml/yaml_fail.go#L1-L18","documentation":"This is the entire payload of the testify_yaml_fail build-tag implementation (assert/yaml/yaml_fail.go). When the module is compiled with -tags testify_yaml_fail, the yaml subpackage is replaced by a stub whose Unmarshal always returns this error. It is a deliberate opt-in to exclude gopkg.in/yaml.v3 from the build (e.g. to satisfy license policy or reduce binary size). It is NOT a runtime defect.","triggerScenarios":"Running tests with `go test -tags testify_yaml_fail` and then calling any assert function that needs YAML (assert.YAMLEq, assert.YAMLEqMap, or objects whose Diff rendering falls back to YAML). The fail-tag stub's Unmarshal returns errNotImplemented unconditionally.","commonSituations":"A CI pipeline or Dockerfile adds the testify_yaml_fail tag globally (via GOFLAGS or Makefile), then a new test starts using YAMLEq. Also happens when a project's build tags were copied from a template without understanding them.","solutions":["If you need YAML assertions, remove the testify_yaml_fail build tag (or switch to testify_yaml_default / testify_yaml_custom).","If you must keep the fail tag, replace YAMLEq assertions with JSON-based equivalents (assert.JSONEq).","Provide a custom YAML implementation by building with -tags testify_yaml_custom and registering your own unmarshaller."],"exampleFix":"// before: run with -tags testify_yaml_fail\n//   assert.YAMLEq(t, yamlStr, got)\n// after: drop the tag, or use JSON\n//   assert.JSONEq(t, jsonStr, got)","handlingStrategy":"validation","validationCode":"// At startup of test files using YAML, fail fast with a clear message:\nvar _ = func() bool {\n    err := yaml.Unmarshal([]byte(\"{}\"), &map[string]interface{}{})\n    if err != nil && err.Error() == \"YAML functions are not available (see https://pkg.go.dev/github.com/stretchr/testify/assert/yaml)\" {\n        log.Println(\"testify built with testify_yaml_fail; YAMLEq unavailable\")\n    }\n    return true\n}()","typeGuard":"// Runtime feature probe:\nfunc yamlAvailable() bool {\n    var m map[string]interface{}\n    return yaml.Unmarshal([]byte(\"{}\"), &m) == nil\n}","tryCatchPattern":"// Branch on availability rather than crashing the suite:\nif !yamlAvailable() {\n    t.Skip(\"YAML assertions disabled in this build\")\n}\nassert.YAMLEq(t, want, got)","preventionTips":["Document which build tags your CI applies and why.","Run a smoke test that exercises one YAMLEq to catch accidental fail-tag usage.","Prefer JSON-based assertions unless YAML is specifically required."],"tags":["yaml","build-tags","configuration","optional-dependency"],"analyzedSha":"001eb7946baf451879253643e4ce4b38eaa0d4a7","analyzedAt":"2026-08-04T21:49:58.715Z","schemaVersion":2}