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#new → WorkflowPresenter#workflow_form_context_props → GumroadAddress.full → COUNTRY.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.
Bug:
GumroadAddress.fullraisesNoMethodErrorand crashes the app on boot whenADDRESS_COUNTRYis misconfiguredWhat
GumroadAddress.fullcrashes withNoMethodError: undefined method 'alpha3' for nilwhen theADDRESS_COUNTRYenvironment variable is set to a value thatISO3166::Country[]cannot resolve — for example a 3-letter code ("USA"instead of"US"), a typo, or a blank string.Because the
COUNTRYconstant 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"]returnsnilfor unrecognized codesnil.alpha3raisesNoMethodErrorDesired behavior:
GumroadAddress.fulldegrades gracefully when the country code is unrecognized, falling back to the raw configured string instead of crashingHow 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/newimmediately crashed with:The crash path:
WorkflowsController#new→WorkflowPresenter#workflow_form_context_props→GumroadAddress.full→COUNTRY.alpha3, whereCOUNTRYwasnilbecauseISO3166::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) andCOUNTRY(ISO lookup result), then uses safe navigation with a fallback inGumroadAddress.full. A spec covering both the happy path and the nil-country fallback is included.