Skip to content

gmtwhich/gmtget: Report a failed download through the exit status - #9197

Merged
Esteban82 merged 2 commits into
masterfrom
fix-9195
Sep 11, 2026
Merged

Esteban82 merged 2 commits into
masterfrom
fix-9195

Conversation

@Esteban82

@Esteban82 Esteban82 commented Sep 11, 2026

Copy link
Copy Markdown
Member

gmt which -G and gmt get -D now exit with the error code from src/gmt_error_codes.h (GMT_FILE_NOT_FOUND = 16) when a requested download didn't produce the file, instead of always exiting 0.

Tested with:

$ gmt which -Ga @nonexistent.nc --GMT_AUTO_DOWNLOAD=off; echo "exit = $?"
...
exit = 16

$ gmt get -Ddata=earth_mask -I1d --GMT_AUTO_DOWNLOAD=off; echo "exit = $?"
...
exit = 16

Fixes #9195

Assisted-by: Claude Sonnet 5, reviewed by Claude Opus 5

Both -G (gmtwhich) and -D (gmtget) already detect a missing file after
gmt_download_file_if_not_found() (the not-found message, and the error
lines it logs) but discarded that outcome and always returned
GMT_NOERROR. Track it instead and return GMT_FILE_NOT_FOUND when a
requested download did not produce the file. Scoped to -G/-D only (a
plain "gmt which localfile" is unaffected) and gmtwhich -C keeps
exiting 0, since its whole point is reporting Y/N as text. Tiled
dataset listings are not covered here.

Fixes #9195

Assisted-by: Claude Sonnet 5
The tiled-dataset branch needs its own JP2-vs-netCDF existence check
(a tile that -N leaves as JP2 is still present), which duplicates
logic gmt_set_remote_and_local_filenames() already gets right
internally. Rather than reimplementing it, leave tiled datasets
unchecked here, same as gmt which -G already does. For the two
remaining checks, use a fixed offset of 1 instead of the return value
of gmt_download_file_if_not_found(): every file name here is built
locally as "@%s", so the offset is always 1.

Assisted-by: Claude Sonnet 5, reviewed by Claude Opus 5
@Esteban82
Esteban82 marked this pull request as ready for review September 11, 2026 02:06
@Esteban82 Esteban82 added the add-changelog Add PR to the changelog label Sep 11, 2026
@Esteban82
Esteban82 merged commit 4872bb2 into master Sep 11, 2026
12 of 14 checks passed
@Esteban82
Esteban82 deleted the fix-9195 branch September 11, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should "gmt which -G" and "gmt get -D" report failed downloads through their exit status?

2 participants