sundowndev/phoneinfoga · error

country code +%d wasn't recognized

Error message

country code +%d wasn't recognized

What it means

OVHSupplier.Search requires num.Country (used as the country code in the OVH API URL) to be non-empty; it lowercases it and appends it to the detailedZones endpoint. If num.CountryCode is set but num.Country is empty, it returns this error, since the numeric country code alone cannot produce the alphabetical country parameter the OVH API expects.

Source

Thrown at lib/remote/suppliers/ovh.go:52

// OVHScannerResponse is the OVH scanner response
type OVHScannerResponse struct {
	Found       bool
	NumberRange string
	City        string
	ZipCode     string
}

type OVHSupplier struct{}

func NewOVHSupplier() *OVHSupplier {
	return &OVHSupplier{}
}

func (s *OVHSupplier) Search(num number.Number) (*OVHScannerResponse, error) {
	countryCode := strings.ToLower(num.Country)

	if countryCode == "" {
		return nil, fmt.Errorf("country code +%d wasn't recognized", num.CountryCode)
	}

	// Build the request
	response, err := http.Get(fmt.Sprintf("https://api.ovh.com/1.0/telephony/number/detailedZones?country=%s", countryCode))
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()

	if response.StatusCode >= 400 {
		var result OVHAPIErrorResponse
		err = json.NewDecoder(response.Body).Decode(&result)
		if err != nil {
			return nil, err
		}
		return nil, errors.New(result.Message)
	}

View on GitHub (pinned to 55807b05b7)

Solutions

  1. Ensure num.Country is populated with an ISO-2 country code (e.g. 'FR') before calling Search
  2. Populate Country from CountryCode via a lookup table or library (e.g. 'github.com/itchyny/goqi' / libphonenumber's GetRegionCodeForCountryCode) at parse time
  3. Validate the number before calling: skip/log numbers with empty Country instead of calling Search
  4. If the number is genuinely unparseable, fall back to another supplier or mark the scan result as unknown

Example fix

// before
res, err := supplier.Search(number.Number{CountryCode: 33})
// after
if num.Country == "" {
    num.Country = regionCodeFor(num.CountryCode) // e.g. 33 -> "FR"
}
res, err := supplier.Search(num)
Defensive patterns

Strategy: validation

Validate before calling

if num.Country == "" {
    return fmt.Errorf("cannot search OVH: number %d has no country", num.CountryCode)
}

Type guard

func hasCountry(num number.Number) bool {
    return num.Country != ""
}

Try / catch

res, err := supplier.Search(num)
if err != nil {
    if strings.Contains(err.Error(), "wasn't recognized") {
        log.Warnf("skipping +%d: missing country code", num.CountryCode)
        return nil, nil // skip this number
    }
    return nil, err
}

Prevention

When it happens

Trigger: Calling Search on a number.Number whose Country field is "" (unparsed/missing) — the message reports the numeric CountryCode that could not be mapped, e.g. 'country code +33 wasn't recognized'.

Common situations: Number parsed by a library that fills CountryCode but not the ISO Country field; caller constructed number.Number manually with only CountryCode; upstream parsing failed silently and Country was never normalized to an ISO code like 'fr' or 'ca'.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of sundowndev/phoneinfoga@55807b05b7 (2026-09-03). Data as JSON: /api/errors/6a670a50463e8fd7. Report an issue: GitHub.