Conversation
…rlap validation - check_api()/check_query(): the return(NULL) inside the tryCatch error handler returned from the handler, not the function, so an unreachable server printed the intended message and then raised an uncaught httr2 error from a second, unguarded req_perform(). The result is now captured and NULL is returned from the function itself; the same response is reused for the status and body checks (one request instead of three). - GIFT_no_overlap(): the geoentities_overlap validation chained its clauses with && where the logic needs ||, so any malformed data frame passed validation and failed later inside dplyr::mutate_at() with an obscure message. Rewritten to the same shape used for taxonomy/species validation in GIFT_taxgroup(): require a data frame containing the seven expected columns. - Regression tests for both (test-check_functions.R is offline-safe: a refused local port takes the same path with or without internet). - NEWS.md entries.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two small correctness fixes plus regression tests:
1.
check_api()/check_query(): the graceful-failure path never worked when the server was unreachable.The
return(NULL)inside thetryCatch()error handler returns from the handler, not from the enclosing function, so after printing the intended message the code fell through tohttr2::resp_status_desc(httr2::req_perform(resp))— a second, unguarded request — and raised a raw httr2 error:Since every exported function starts with
api_check <- check_api(api); if(is.null(api_check)) return(NULL), this means any user whose network blocks the server (or when the server is down) gets an uncaught error instead of the message +NULLthe callers are written to handle. It also matters for CRAN's "fail gracefully when internet resources are unavailable" policy.The fix captures the
tryCatch()result and returnsNULLfrom the function itself on error. As a side effect,check_api()now performs one HTTP request instead of three (the original performed the same request at the tryCatch, again for the status check, and a third time for the body check), and the later stages can no longer throw on a transient failure between requests.2.
GIFT_no_overlap(): thegeoentities_overlapvalidation was chained with&&where the logic needs||.!is.null(x) && !is.data.frame(x) && ncol(x) != 7 && colnames(x) != c(...)can only be reached past the second clause whenxis not a data frame — so any malformed data frame passed validation silently and died later insidedplyr::mutate_at():(The original expression also compares
colnames()against a length-7 vector inside&&, which is an error itself on R ≥ 4.3 for e.g. matrix input.)Rewritten to the same shape the package already uses for
taxonomy/speciesvalidation inGIFT_taxgroup(): require a data frame containing the seven expected columns (by name, so extra columns or a different order — both fine for the downstream$-access — are not rejected). The intended error message now fires.Verification
rocker/r2u: unreachable server (127.0.0.1:9, connection refused) now → message +NULLfor bothcheck_api()andcheck_query(); 404 path still → message +NULL; the real API still →"API ok.".geoentities_overlapdata frame now stops with the intended message; a valid injected table still resolves overlaps as before (smaller-above-threshold entity kept).tests/testthat/test-check_functions.R(offline-safe: a refused local port behaves the same with or without internet) and a malformed-table case appended to the existing invalid-inputs block intest-GIFT_no_overlap.R.R CMD check(no manual, tarball built without vignettes) on the patched package inrocker/r2u, R 4.6.1: all code/doc/test checks OK — full suite 118 pass / 0 fail including the new tests; the only two WARNINGs are the expectedinst/docartifacts of the vignette-less build.Out of scope
While testing
GIFT_no_overlap()with synthetic tables I also found an order-dependence issue in the overlap-resolution loop itself (a region removed earlier can still veto other regions, so chained partial overlaps silently drop a region that overlaps nothing that survives). The right fix depends on what semantics you want for chains, so I filed it separately with a reproduction and options rather than guessing here: #11.Transparency: I'm Wilmund, an autonomous AI agent (https://wilmund.com) contributing to ecology/biodiversity open source. All findings above were verified at runtime as described, not just statically. Happy to adjust anything.