{"record":{"id":"9b42cdb361e42110","repo":"kataras/iris","slug":"asset-read-file-w","errorCode":null,"errorMessage":"asset: read file: %w","messagePattern":"asset: read file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"view/fs.go","lineNumber":56,"sourceCode":"\n\t\tif info.IsDir() {\n\t\t\treturn nil\n\t\t}\n\n\t\twalkFnErr := walkFn(path, info, err)\n\t\tif walkFnErr != nil {\n\t\t\treturn fmt.Errorf(\"walk: walkFn: %w\", walkFnErr)\n\t\t}\n\n\t\treturn nil\n\t})\n\n}\n\nfunc asset(fileSystem fs.FS, name string) ([]byte, error) {\n\tdata, err := fs.ReadFile(fileSystem, name)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"asset: read file: %w\", err)\n\t}\n\n\treturn data, nil\n}\n\nfunc getFS(fsOrDir any) fs.FS {\n\treturn context.ResolveFS(fsOrDir)\n}\n\nfunc getRootDirName(fileSystem fs.FS) string {\n\trootDirFile, err := fileSystem.Open(\".\")\n\tif err == nil {\n\t\trootDirStat, err := rootDirFile.Stat()\n\t\tif err == nil {\n\t\t\treturn rootDirStat.Name()\n\t\t}\n\t}\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/view/fs.go#L38-L74","documentation":"The internal asset helper reads a single file from an fs.FS and wraps any fs.ReadFile failure as 'asset: read file: <err>'. It is used when fetching embedded or on-disk view/asset files, giving callers a clear point of failure with the underlying OS/FS error preserved via %w.","triggerScenarios":"Get (or an anonymous loader using asset) requests a name that does not exist in the filesystem, is a directory, or cannot be opened — fs.ReadFile returns ErrNotExist/permission error and it is wrapped here.","commonSituations":"Requesting a template path with wrong extension or leading slash (io/fs requires clean, slash-separated, no-leading-slash names), asset not included in embed.FS, or file deleted from a deployed image.","solutions":["Use the exact relative, slash-separated path with no leading slash (e.g. 'views/index.html').","Verify the file is present in the FS/embed directive (embed must list it via //go:embed pattern).","Check the wrapped error: os.ErrNotExist means wrong name; EACCES means permissions.","In callers, guard with fs.Stat or errors.Is(err, fs.ErrNotExist) and fall back to a default asset."],"exampleFix":"// before\nasset(fsys, \"/views/index.html\") // leading slash invalid in io/fs\n// after\nasset(fsys, \"views/index.html\")","handlingStrategy":"fallback","validationCode":"name = strings.TrimPrefix(name, \"/\") // io/fs requires clean relative paths\nif _, err := fs.Stat(fileSystem, name); err != nil {\n    return fallbackAsset(name)\n}","typeGuard":"func assetExists(fsys fs.FS, name string) bool {\n    _, err := fs.Stat(fsys, name)\n    return err == nil\n}","tryCatchPattern":"data, err := asset(fsys, name)\nif err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n        return defaultAsset, nil // serve fallback\n    }\n    return nil, fmt.Errorf(\"asset %s: %w\", name, err)\n}","preventionTips":["Always pass slash-separated relative paths with no leading slash to io/fs APIs.","Verify //go:embed patterns actually include the asset files.","Guard reads with fs.Stat and fall back to a bundled default when missing."],"tags":["filesystem","assets","io"],"backgroundTag":"file-not-found","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}