owasp-amass/amass · error

failed to obtain the path for the output directory

Error message

failed to obtain the path for the output directory

What it means

CreateOutputDirectory resolves the output directory path via config.OutputDirectory(dirpath). If that returns an empty string (no usable path could be derived), the function returns this error rather than attempting to create a directory at an unknown location.

Source

Thrown at internal/tools/file.go:22

package tools

import (
	"errors"
	"fmt"
	"io"
	"os"
	"path/filepath"

	"github.com/owasp-amass/amass/v5/config"
	"github.com/owasp-amass/amass/v5/resources"
)

func CreateOutputDirectory(dirpath string) error {
	// Prepare output file paths
	dir := config.OutputDirectory(dirpath)
	if dir == "" {
		return errors.New("failed to obtain the path for the output directory")
	}
	// If the directory does not yet exist, create it
	if err := os.MkdirAll(dir, 0755); err != nil {
		return fmt.Errorf("mkdir failed for %s: %v", dir, err)
	}
	// ensure that the permissions are set correctly
	if err := os.Chmod(dir, 0755); err != nil {
		return fmt.Errorf("failed to set permissions to 0755 for %s: %v", dir, err)
	}
	return nil
}

func CreateDefaultConfigFiles(dirpath string) error {
	for _, filename := range resources.DefaultFilesList {
		filepath := filepath.Join(dirpath, filename)
		if _, err := os.Stat(filepath); !os.IsNotExist(err) {
			// If the file already exists, skip creating it
			continue

View on GitHub (pinned to 79299dce87)

Solutions

  1. Pass an explicit non-empty dirpath argument to CreateOutputDirectory.
  2. Set the output directory in the Amass config or set HOME so config.OutputDirectory can resolve a default.
  3. Check config.OutputDirectory() directly to see why it returns empty before calling this function.

Example fix

// before
err = tools.CreateOutputDirectory("")
// after
dir := flagOutput
if dir == "" {
    dir = filepath.Join(os.Getenv("HOME"), "amass_output")
}
err = tools.CreateOutputDirectory(dir)
Defensive patterns

Strategy: validation

Validate before calling

if dirpath == "" && config.OutputDirectory("") == "" {
    return errors.New("no output directory configured; pass -d or set HOME")
}
err := tools.CreateOutputDirectory(dirpath)

Prevention

When it happens

Trigger: Calling CreateOutputDirectory with an empty dirpath when no default output directory is configured, or config.OutputDirectory failing to resolve HOME/env-based paths and returning "".

Common situations: Running the tool in an environment without a home directory (e.g. containers, cron, CI with HOME unset); passing an empty --output/-d flag while no config default exists.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


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