projectdiscovery/subfinder · error
max-results cannot be negative
Error message
max-results cannot be negative
What it means
validateOptions enforces that the per-source results limit (max-results) is not negative. A negative MaxResults is meaningless as a cap, so option parsing fails fast with this error before enumeration starts.
Solutions
- Pass a non-negative integer for -max-results
- Omit the flag entirely to use the default limit
- Validate any computed limit value before passing it to the runner
Example fix
// before subfinder -d example.com -max-results -5 // after subfinder -d example.com -max-results 100
Defensive patterns
Strategy: validation
Validate before calling
if maxResults < 0 {
return fmt.Errorf("max-results must be >= 0, got %d", maxResults)
} Type guard
func validMaxResults(n int) bool { return n >= 0 } Try / catch
opts, err := runner.ParseOptions()
if err != nil && strings.Contains(err.Error(), "max-results cannot be negative") {
// fix flag value and retry parse
} Prevention
- Never pass negative integers to -max-results
- Validate computed limits in scripts before invoking subfinder
- Rely on defaults when unsure
When it happens
Trigger: Supplying -max-results with a negative integer on the CLI, or programmatically setting Options.MaxResults < 0 before ParseOptions runs validation.
Common situations: Shell scripts computing the limit with variables that can go negative; typos like '-5' intended as a flag; copied config files with negative values.
Understand the failure class
Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.
Related errors
AI-assisted analysis of projectdiscovery/subfinder@7a0b91f0fa (2026-09-06).
Data as JSON: /api/errors/83a185df88b7b92b.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/runner/validate.go:45
return errors.New("both verbose and silent mode specified")
}
// Validate threads and options
if options.Threads == 0 {
return errors.New("threads cannot be zero")
}
if options.Timeout == 0 {
return errors.New("timeout cannot be zero")
}
// Always remove wildcard with hostip
if options.HostIP && !options.RemoveWildcard {
return errors.New("hostip flag must be used with RemoveWildcard option")
}
// The per-source results limit cannot be negative.
if options.MaxResults < 0 {
return fmt.Errorf("max-results cannot be negative")
}
// The response body size limit cannot be negative.
if options.MaxResponseBodySize < 0 {
return fmt.Errorf("response-size-read cannot be negative")
}
if options.Match != nil {
options.matchRegexes = make([]*regexp.Regexp, len(options.Match))
var err error
for i, re := range options.Match {
if options.matchRegexes[i], err = regexp.Compile(stripRegexString(re)); err != nil {
return errors.New("invalid value for match regex option")
}
}
}
if options.Filter != nil {
options.filterRegexes = make([]*regexp.Regexp, len(options.Filter))View on GitHub (pinned to 7a0b91f0fa)