owasp-amass/amass · error

ASN parsing failed

Error message

ASN parsing failed

What it means

ParseASNs is a flag.Value implementation for comma-separated ASN flags. Set rejects an empty string with this error; otherwise each token has an optional "AS" prefix stripped (via TrimPrefix after trimming whitespace) and parsed with strconv.Atoi. Any token that is not numeric aborts the whole flag.

Source

Thrown at internal/afmt/parse.go:196

func (p *ParseASNs) String() string {
	if p == nil {
		return ""
	}
	var builder strings.Builder
	for i, n := range *p {
		if i > 0 {
			builder.WriteRune(',')
		}
		builder.WriteString(strconv.Itoa(n))
	}
	return builder.String()
}

// Set implements the flag.Value interface.
func (p *ParseASNs) Set(s string) error {
	if s == "" {
		return fmt.Errorf("ASN parsing failed")
	}

	asns := strings.Split(s, ",")
	for _, asn := range asns {
		i, err := strconv.Atoi(strings.TrimPrefix(strings.TrimSpace(asn), "AS"))
		if err != nil {
			return err
		}
		*p = append(*p, i)
	}
	return nil
}

View on GitHub (pinned to 79299dce87)

Solutions

  1. Provide comma-separated numeric ASNs, with or without the AS prefix: "AS13335,15169".
  2. Strip whitespace and non-digit characters from each token before passing.
  3. Confirm the feeding variable is non-empty before invocation.

Example fix

// before
-asn "$ASNS"                # empty -> ASN parsing failed
// after
-asn "AS13335,AS15169"
Defensive patterns

Strategy: validation

Validate before calling

func validateASNsFlag(value string) error {
	if strings.TrimSpace(value) == "" {
		return errors.New("flag requires a non-empty ASN list")
	}
	for _, a := range strings.Split(value, ",") {
		if _, err := strconv.Atoi(strings.TrimPrefix(strings.TrimSpace(a), "AS")); err != nil {
			return fmt.Errorf("token %q is not a valid ASN", a)
		}
	}
	return nil
}

Type guard

func isASNToken(s string) bool { _, err := strconv.Atoi(strings.TrimPrefix(strings.TrimSpace(s), "AS")); return err == nil }

Prevention

When it happens

Trigger: Calling Set("") on a *ParseASNs, or tokens like "AS123x", "AS ", "AS13335,foo", or numbers exceeding platform int range.

Common situations: Paste with stray characters or spaces after "AS", lists joined with semicolons or spaces instead of commas, empty environment variables in scripted runs.

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 owasp-amass/amass@79299dce87 (2026-09-06). Data as JSON: /api/errors/6c12551fc3aa4d23. Report an issue: GitHub.