projectdiscovery/subfinder · error

empty filename

Error message

empty filename

What it means

Guard in OutputWriter.createFile that fires when the output filename argument is the empty string, i.e. no -o/-oO output path was actually supplied to the file-writing path. It is a sentinel validation error raised before os.Create/os.OpenFile is attempted.

Solutions

  1. Check that the -o or -oN/-oJ/-oH output flag carries a non-empty path before invoking the outputter
  2. Default the filename to a sane value (e.g. derived from the domain) when the caller passes an empty string
  3. Treat an empty filename as 'write to stdout' instead of routing it into createFile
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/runner/outputter.go:50 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of projectdiscovery/subfinder@7a0b91f0fa (2026-09-06). Data as JSON: /api/errors/b2ac3f17c9f7c2e5. Report an issue: GitHub.

Appendix: source

Thrown at pkg/runner/outputter.go:50

	Source              string `json:"source"`
	WildcardCertificate bool   `json:"wildcard_certificate,omitempty"`
}

type jsonSourcesResult struct {
	Host                string   `json:"host"`
	Input               string   `json:"input"`
	Sources             []string `json:"sources"`
	WildcardCertificate bool     `json:"wildcard_certificate,omitempty"`
}

// NewOutputWriter creates a new OutputWriter
func NewOutputWriter(json bool) *OutputWriter {
	return &OutputWriter{JSON: json}
}

func (o *OutputWriter) createFile(filename string, appendToFile bool) (*os.File, error) {
	if filename == "" {
		return nil, errors.New("empty filename")
	}

	dir := filepath.Dir(filename)

	if dir != "" {
		if _, err := os.Stat(dir); os.IsNotExist(err) {
			err := os.MkdirAll(dir, os.ModePerm)
			if err != nil {
				return nil, err
			}
		}
	}

	var file *os.File
	var err error
	if appendToFile {
		file, err = os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
	} else {

View on GitHub (pinned to 7a0b91f0fa)