FiloSottile/age · error

data part too short

Error message

data part too short

What it means

A valid bech32 string needs at least 6 data-part characters (the checksum) beyond the HRP. If fewer than 6 characters follow the separator, there is not even a full checksum to verify, so Decode fails early.

Source

Thrown at internal/bech32/bech32.go:170

	for p, c := range hrp {
		if c < 33 || c > 126 {
			return "", nil, fmt.Errorf("invalid character human-readable part: s[%d]=%d", p, c)
		}
	}
	for p, c := range s[pos+1:] {
		// Fold ASCII explicitly. Unicode case folding can turn a non-ASCII
		// rune into a shorter valid charset member.
		if c >= 'A' && c <= 'Z' {
			c += 'a' - 'A'
		}
		d := strings.IndexRune(charset, c)
		if d == -1 {
			return "", nil, fmt.Errorf("invalid character data part: s[%d]=%v", p, c)
		}
		data = append(data, byte(d))
	}
	if len(data) < 6 {
		return "", nil, fmt.Errorf("data part too short")
	}
	if !verifyChecksum(hrp, data) {
		return "", nil, fmt.Errorf("invalid checksum")
	}
	data, err = convertBits(data[:len(data)-6], 5, 8, false)
	if err != nil {
		return "", nil, err
	}
	return hrp, data, nil
}

View on GitHub (pinned to b74dce4cdb)

Solutions

  1. Re-copy the complete key; the string was truncated
  2. Check that log/UI truncation (e.g. '...') did not remove the tail
  3. Validate length before decoding: last '1' + 7 chars minimum
Defensive patterns

Strategy: validation

Validate before calling

if len(s)-strings.LastIndex(s, "1")-1 < 6 {
    return errors.New("bech32 data part too short; input likely truncated")
}

Prevention

When it happens

Trigger: Decode with strings like "age1q" or "hrp12345" (only 5 data chars) — anything with len(s)-pos-1 < 6.

Common situations: Truncated keys from copy/paste or message length limits, hand-trimmed strings that cut the tail of an address.

Related errors


AI-assisted analysis of FiloSottile/age@b74dce4cdb (2026-08-31). Data as JSON: /api/errors/b5b326786a9f5983. Report an issue: GitHub.