Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages #30

Merged
merged 9 commits into from
Oct 11, 2024
Merged

Improve error messages #30

merged 9 commits into from
Oct 11, 2024

Conversation

rcannood
Copy link
Collaborator

@rcannood rcannood commented Oct 10, 2024

Changes

@rcannood rcannood changed the title Alternative-error Improve error messages Oct 10, 2024
@rcannood rcannood requested a review from lazappi October 11, 2024 07:45
R/InstanceAPI.R Outdated
if (httr::http_error(request)) {
cli_abort(content$detail)
}
request <- httr::GET(url)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be "response" rather than "request"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

R/InstanceAPI.R Outdated
Comment on lines 99 to 106
process_request = function(request, request_type) {
content <- httr::content(request)
if (httr::http_error(request)) {
cli_abort(content$detail)
if (is.list(content) && "detail" %in% names(content)) {
cli_abort(content$detail)
} else {
cli_abort(paste0("Failed to ", request_type, " from instance. Response output: ", content))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this will work with the API package but we can sort that out later

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

cli_abort("Missing column: ", missing_column)
missing_key <- setdiff(expected_keys, names(settings))
if (length(missing_key) > 0) {
cli_abort(paste0("Missing key: ", paste(missing_key, collapse = ", ")))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing keys? I think {cli} can automatically pluralise stuff if you want to get fancy but not sure it's worth the effort.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is cool, I didn't know {cli} could do this!

)
}

test_that("test get_schema", {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not important but I think you are supposed to read this as a sentence starting with "Test that..." so the extra "test" is a bit redundant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

@rcannood rcannood requested a review from lazappi October 11, 2024 09:22
if (length(missing_column) > 0) {
cli_abort("Missing column: ", missing_column)
missing_keys <- setdiff(expected_keys, names(settings))
if (length(missing_key) > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a s here

Suggested change
if (length(missing_key) > 0) {
if (length(missing_keys) > 0) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would accept this suggestion but already fixed it myself based on the feedback you gave

@rcannood rcannood merged commit 11aedcb into main Oct 11, 2024
7 checks passed
@rcannood rcannood deleted the alternative-error branch October 11, 2024 09:55
lazappi added a commit that referenced this pull request Oct 14, 2024
* origin/main:
  Add printing to remaining classes (#31)
  Improve error messages (#30)
  Update documentation (#29)
  Return `NULL` when a record's related field is empty (#28)
  minor fix in usage vignette (#32)
  Add usage vignette (#18)
  Add a simple unit test which queries laminlabs/lamindata (#27)
  bump action from v4.5.0 to v4 (#26)
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.

2 participants