{"record":{"id":"c4c60c4e60c19fba","repo":"kubernetes/kops","slug":"reading-embedded-file-q-w","errorCode":null,"errorMessage":"reading embedded file %q: %w","messagePattern":"reading embedded file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/assets/assetdata/data.go","lineNumber":49,"sourceCode":"//go:embed *.yaml\nvar embeddedDataFS embed.FS\n\n// GetHash returns the stored hash for the well-known asset, looking it up by the canonicalURL.\n// If found, it returns (hash, true, nil)\n// If not found, it returns (nil, false, nil)\nfunc GetHash(canonicalURL *url.URL) (*hashing.Hash, bool, error) {\n\tvar allMatches []*file\n\n\tif err := fs.WalkDir(embeddedDataFS, \".\", func(p string, d fs.DirEntry, err error) error {\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif d.IsDir() {\n\t\t\treturn nil\n\t\t}\n\t\tb, err := fs.ReadFile(embeddedDataFS, p)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"reading embedded file %q: %w\", p, err)\n\t\t}\n\n\t\tmanifest, err := parseManifestFile(b)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"parsing embedded file %q: %w\", p, err)\n\t\t}\n\n\t\tmatches := manifest.Matches(canonicalURL.String())\n\t\tallMatches = append(allMatches, matches...)\n\t\treturn nil\n\t}); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"walking embedded data: %w\", err)\n\t}\n\n\thashes := sets.New[string]()\n\tfor _, match := range allMatches {\n\t\thashes.Insert(match.SHA256)\n\t}","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/assets/assetdata/data.go#L31-L67","documentation":"GetHash walks the go:embed filesystem of assetdata and reads every embedded YAML manifest. This error wraps any fs.ReadFile failure encountered while reading an embedded file during that walk. Because the files are compiled into the binary, this almost always indicates a corrupted/inconsistent build or an fs abstraction failure rather than a runtime disk problem.","triggerScenarios":"Calling assetdata.GetHash when fs.ReadFile fails on an embedded path during the WalkDir callback — e.g. the embed.FS was populated inconsistently at build time or a path race/IO error occurs while walking.","commonSituations":"Broken/incomplete go build cache or corrupted binary; embedding directives changed (//go:embed *.yaml) so a file vanished mid-build; running an artifact built on a damaged filesystem.","solutions":["Rebuild the kops binary with a clean build cache: go clean -cache && make kops","Verify the binary embeds the manifests: go:embed *.yaml files exist under pkg/assets/assetdata/","Re-download or re-install the kops release binary if the checksum mismatches","Report a bug with the wrapped inner error if it persists on a fresh official build"],"exampleFix":"// before: using a damaged third-party build\n./kops-with-broken-embed get assets\n// after: rebuild from source\ngo clean -cache && make kops && ./kops get assets","handlingStrategy":"try-catch","validationCode":"// Embedded FS cannot be validated at runtime; verify the build instead:\n// go test ./pkg/assets/assetdata/ -run TestGetHash\nif _, ok := interface{}(err).(*fs.PathError); ok { /* embedded FS read failure */ }","typeGuard":"func isFSErr(err error) bool {\n\tvar pe *fs.PathError\n\treturn errors.As(err, &pe)\n}","tryCatchPattern":"h, found, err := assetdata.GetHash(u)\nif err != nil {\n\tif isFSErr(err) {\n\t\t// fail fast: binary asset data is corrupt; do not retry\n\t\treturn fmt.Errorf(\"asset data unreadable, rebuild binary: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Run TestGetHash in CI to validate embedded manifests after every build","Verify binary checksums before deploying kops artifacts","Avoid mutating go:embed source files outside the generator","Rebuild from clean cache if embed-related errors appear"],"tags":["embedded-files","filesystem","kops"],"backgroundTag":"embedded-asset-read-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}