owasp-amass/amass · error

failed to obtain the embedded file: %s: %v

Error message

failed to obtain the embedded file: %s: %v

What it means

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.

Source

Thrown at resources/resources.go:27

	"fmt"
	"io/fs"
)

//go:embed alterations.txt config.yaml datasources.yaml namelist.txt
var resourceFS embed.FS

var DefaultFilesList = []string{
	"alterations.txt",
	"config.yaml",
	"datasources.yaml",
	"namelist.txt",
}

func GetResourceFile(path string) (fs.File, error) {
	file, err := resourceFS.Open(path)

	if err != nil {
		return nil, fmt.Errorf("failed to obtain the embedded file: %s: %v", path, err)
	}

	return file, err
}

func GetResourceFileData(path string) ([]byte, error) {
	return resourceFS.ReadFile(path)
}

View on GitHub (pinned to 79299dce87)

Solutions

  1. Pass exactly one of the names in resources.DefaultFilesList: "alterations.txt", "config.yaml", "datasources.yaml", "namelist.txt" - no directory prefix, no leading slash
  2. 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)
  3. 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
  4. Rebuild the binary (go build) if resources were recently added to the //go:embed directive, since embedded content is fixed at compile time

Example fix

// before
f, err := resources.GetResourceFile("/etc/amedas/config.yaml")

// after
f, err := resources.GetResourceFile("config.yaml") // one of resources.DefaultFilesList
Defensive patterns

Strategy: validation

Validate before calling

func isEmbeddedResource(path string) bool {
	return slices.Contains(resources.DefaultFilesList, path)
}

if !isEmbeddedResource(path) {
	return fmt.Errorf("%q is not an embedded resource; valid: %v", path, resources.DefaultFilesList)
}

Type guard

func validResourcePath(path string) bool {
	for _, name := range resources.DefaultFilesList {
		if path == name {
			return true
		}
	}
	return false
}

Try / catch

f, err := resources.GetResourceFile(path)
if err != nil {
	var perr *fs.PathError
	if errors.As(err, &perr) && errors.Is(perr.Err, fs.ErrNotExist) {
		// path is not an embedded asset; fall back to os.Open or a default
	}
	return fmt.Errorf("loading resource %q: %w", path, err)
}
defer f.Close()

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06). Data as JSON: /api/errors/869fdf260e9a84d7. Report an issue: GitHub.