Skip to content

Handle empty/incomplete gcloud config file gracefully#192

Open
mattwynne wants to merge 1 commit intopeburrows:masterfrom
mechanical-orchard:handle-empty-gcloud-config/sc-107985
Open

Handle empty/incomplete gcloud config file gracefully#192
mattwynne wants to merge 1 commit intopeburrows:masterfrom
mechanical-orchard:handle-empty-gcloud-config/sc-107985

Conversation

@mattwynne
Copy link
Copy Markdown

@mattwynne mattwynne commented Apr 9, 2026

Summary

When ~/.config/gcloud/configurations/config_default exists but is empty or missing the required [core] section (e.g. after running gcloud auth list on a fresh install), get_configuration_data/1 crashes trying to access keys on a nil/empty map. This crashes the GenServer with a CaseClauseError and prevents any fallback credential sources from being tried.

This change makes get_configuration_data/1 pattern-match for the expected structure and return nil when it's not present, with a warning log that tells the user how to fix it. This lets the credential fallback chain in from_gcloud_adc/1 continue to metadata or other sources.

Before

** (CaseClauseError) no case clause matching: :error
    (goth 1.4.5) lib/goth/token.ex:252: Goth.Token.request/1

After

[warning] Gcloud configuration file ... is missing required [core] section
with project and account settings. Run 'gcloud init' or delete this file to resolve.

And Goth continues to try other credential sources.

Licensing:
This contribution is made by employees of Mechanical Orchard, Inc. under the terms of the project's license.

When ~/.config/gcloud/configurations/config_default
exists but is empty or missing the [core] section,
return nil with a warning log instead of crashing.
This lets the credential fallback chain continue.
@mattwynne mattwynne marked this pull request as ready for review April 9, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant