{"record":{"id":"869fdf260e9a84d7","repo":"owasp-amass/amass","slug":"failed-to-obtain-the-embedded-file-s-v-869fdf","errorCode":null,"errorMessage":"failed to obtain the embedded file: %s: %v","messagePattern":"failed to obtain the embedded file: (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resources.go","lineNumber":27,"sourceCode":"\t\"fmt\"\n\t\"io/fs\"\n)\n\n//go:embed alterations.txt config.yaml datasources.yaml namelist.txt\nvar resourceFS embed.FS\n\nvar DefaultFilesList = []string{\n\t\"alterations.txt\",\n\t\"config.yaml\",\n\t\"datasources.yaml\",\n\t\"namelist.txt\",\n}\n\nfunc GetResourceFile(path string) (fs.File, error) {\n\tfile, err := resourceFS.Open(path)\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to obtain the embedded file: %s: %v\", path, err)\n\t}\n\n\treturn file, err\n}\n\nfunc GetResourceFileData(path string) ([]byte, error) {\n\treturn resourceFS.ReadFile(path)\n}\n","sourceCodeStart":9,"sourceCodeEnd":36,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/resources/resources.go#L9-L36","documentation":"This error wraps a failure from Go's embedded filesystem (//go:embed) when opening one of the resources bundled into the binary (alterations.txt, config.yaml, datasources.yaml, namelist.txt). The library throws it when resourceFS.Open(path) fails, meaning the requested path does not exist in the embedded FS or the path is malformed. Because the files are compiled in via embed, the failure is never about disk permissions or runtime filesystem state - it is always about the path argument not matching an embedded resource.","triggerScenarios":"Calling GetResourceFile (directly, or indirectly via processInputFiles or CreateDefaultConfigFiles) with a path that is not one of the four embedded files, a path with a leading slash or './' prefix (embed.FS paths are relative and rooted at the package directory), a path containing '..' traversal segments, or a name that is not in the //go:embed directive (so it was never compiled into the binary).","commonSituations":"A developer passes an absolute path like /etc/amedas/config.yaml expecting the function to read from disk when it only reads embedded resources; a caller misspells an embedded filename (e.g. 'alteration.txt' instead of 'alterations.txt'); the binary was built from a tree where the embed directive was modified and a resource file was removed; or a caller builds the path dynamically with directory prefixes that embed.FS does not resolve.","solutions":["Pass exactly one of the names in resources.DefaultFilesList: \"alterations.txt\", \"config.yaml\", \"datasources.yaml\", \"namelist.txt\" - no directory prefix, no leading slash","Check the error's wrapped %v part: fs.ErrNotExist confirms the path is not embedded; fix the spelling/casing (embed FS paths are case-sensitive)","If you need to read a user file from disk, use os.Open/fs.Open instead of GetResourceFile, which only serves compile-time embedded assets","Rebuild the binary (go build) if resources were recently added to the //go:embed directive, since embedded content is fixed at compile time"],"exampleFix":"// before\nf, err := resources.GetResourceFile(\"/etc/amedas/config.yaml\")\n\n// after\nf, err := resources.GetResourceFile(\"config.yaml\") // one of resources.DefaultFilesList","handlingStrategy":"validation","validationCode":"func isEmbeddedResource(path string) bool {\n\treturn slices.Contains(resources.DefaultFilesList, path)\n}\n\nif !isEmbeddedResource(path) {\n\treturn fmt.Errorf(\"%q is not an embedded resource; valid: %v\", path, resources.DefaultFilesList)\n}","typeGuard":"func validResourcePath(path string) bool {\n\tfor _, name := range resources.DefaultFilesList {\n\t\tif path == name {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}","tryCatchPattern":"f, err := resources.GetResourceFile(path)\nif err != nil {\n\tvar perr *fs.PathError\n\tif errors.As(err, &perr) && errors.Is(perr.Err, fs.ErrNotExist) {\n\t\t// path is not an embedded asset; fall back to os.Open or a default\n\t}\n\treturn fmt.Errorf(\"loading resource %q: %w\", path, err)\n}\ndefer f.Close()","preventionTips":["Only pass names from resources.DefaultFilesList to GetResourceFile","Remember embed.FS paths are relative, rooted at the resources package directory - strip any absolute or './' prefixes before calling","Do not use GetResourceFile for user-supplied or on-disk file paths; it only serves compile-time embedded assets","Iterate DefaultFilesList (as CreateDefaultConfigFiles does) instead of hardcoding filenames that can drift from the //go:embed directive"],"tags":["go","embed","embedded-files","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}