Skip to content

NoMethodError crash in GumroadAddress.full when ADDRESS_COUNTRY env var is unrecognized #4320

@meet-01

Description

@meet-01

Bug: GumroadAddress.full raises NoMethodError and crashes the app on boot when ADDRESS_COUNTRY is misconfigured

What

GumroadAddress.full crashes with NoMethodError: undefined method 'alpha3' for nil when the ADDRESS_COUNTRY environment variable is set to a value that ISO3166::Country[] cannot resolve — for example a 3-letter code ("USA" instead of "US"), a typo, or a blank string.

Because the COUNTRY constant is evaluated inside a Rails initializer at boot time, a bad value prevents the entire app from starting. Every request returns a 500 until the env var is corrected.

Current behavior:

  • ISO3166::Country["XX"] returns nil for unrecognized codes
  • nil.alpha3 raises NoMethodError
  • App fails to boot

Desired behavior:

  • GumroadAddress.full degrades gracefully when the country code is unrecognized, falling back to the raw configured string instead of crashing

How I encountered this

I was setting up Gumroad locally for the first time on Windows (WSL + Docker), following the standard setup steps. After seeding the database and logging in as seller@gumroad.com, navigating to /workflows/new immediately crashed with:

NoMethodError: undefined method 'alpha3' for nil
config/initializers/gumroad.rb:41:in 'GumroadAddress.full'

The crash path: WorkflowsController#newWorkflowPresenter#workflow_form_context_propsGumroadAddress.fullCOUNTRY.alpha3, where COUNTRY was nil because ISO3166::Country[] didn't resolve the configured value in my local environment.

Why

The default value "US" protects production, but gives no safety net against misconfiguration. Local development and new environments (staging, preview deploys) are common places where env vars are missing or set to placeholders. A boot-time crash from a single bad config value is a disproportionate failure mode — it takes the whole app down rather than degrading a single feature.

I have a fix ready on my fork: meet-01:fix/gumroad-address-nil-country-crash. It splits the constant into COUNTRY_CODE (raw string) and COUNTRY (ISO lookup result), then uses safe navigation with a fallback in GumroadAddress.full. A spec covering both the happy path and the nil-country fallback is included.

Metadata

Metadata

Assignees

No one assigned

    Labels

    planningNeeds to be planned by design, engineering, product, support, and the CEO!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions