{"record":{"id":"e002588a0a357462","repo":"owasp-amass/amass","slug":"failed-to-obtain-the-path-for-the-output-directory","errorCode":null,"errorMessage":"failed to obtain the path for the output directory","messagePattern":"failed to obtain the path for the output directory","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/file.go","lineNumber":22,"sourceCode":"\npackage tools\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\t\"path/filepath\"\n\n\t\"github.com/owasp-amass/amass/v5/config\"\n\t\"github.com/owasp-amass/amass/v5/resources\"\n)\n\nfunc CreateOutputDirectory(dirpath string) error {\n\t// Prepare output file paths\n\tdir := config.OutputDirectory(dirpath)\n\tif dir == \"\" {\n\t\treturn errors.New(\"failed to obtain the path for the output directory\")\n\t}\n\t// If the directory does not yet exist, create it\n\tif err := os.MkdirAll(dir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"mkdir failed for %s: %v\", dir, err)\n\t}\n\t// ensure that the permissions are set correctly\n\tif err := os.Chmod(dir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to set permissions to 0755 for %s: %v\", dir, err)\n\t}\n\treturn nil\n}\n\nfunc CreateDefaultConfigFiles(dirpath string) error {\n\tfor _, filename := range resources.DefaultFilesList {\n\t\tfilepath := filepath.Join(dirpath, filename)\n\t\tif _, err := os.Stat(filepath); !os.IsNotExist(err) {\n\t\t\t// If the file already exists, skip creating it\n\t\t\tcontinue","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/internal/tools/file.go#L4-L40","documentation":"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.","triggerScenarios":"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 \"\".","commonSituations":"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.","solutions":["Pass an explicit non-empty dirpath argument to CreateOutputDirectory.","Set the output directory in the Amass config or set HOME so config.OutputDirectory can resolve a default.","Check config.OutputDirectory() directly to see why it returns empty before calling this function."],"exampleFix":"// before\nerr = tools.CreateOutputDirectory(\"\")\n// after\ndir := flagOutput\nif dir == \"\" {\n    dir = filepath.Join(os.Getenv(\"HOME\"), \"amass_output\")\n}\nerr = tools.CreateOutputDirectory(dir)","handlingStrategy":"validation","validationCode":"if dirpath == \"\" && config.OutputDirectory(\"\") == \"\" {\n    return errors.New(\"no output directory configured; pass -d or set HOME\")\n}\nerr := tools.CreateOutputDirectory(dirpath)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit output directory in scripts and CI.","Set HOME in containers/cron environments.","Resolve and log config.OutputDirectory() at startup to fail fast."],"tags":["filesystem","configuration","go"],"backgroundTag":"missing-required-config","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}