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

transition to cli errors #785

Merged
merged 6 commits into from
Apr 10, 2024
Merged

transition to cli errors #785

merged 6 commits into from
Apr 10, 2024

Conversation

simonpcouch
Copy link
Collaborator

Closes #627.

@@ -14,11 +14,10 @@ OdbcConnection <- function(
timeout = Inf,
dbms.name = NULL,
attributes = NULL,
.connection_string = NULL
.connection_string = NULL,
call = caller_env(2)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using caller_env(2) as caller_env() shows an unhelpful ".local()" frame:

test_con("SQLITE", attributes = list(boop = "bop"))
#> Error in `.local()`:
#> ! `attributes` does not support the connection attribute "boop".
#> ℹ Allowed connection attribute is "azure_token".

with:

 3.   └─odbc::dbConnect(...)
 4.     └─odbc (local) .local(drv, ...)
 5.       └─odbc:::OdbcConnection(...) at odbc/R/dbi-driver.R:184:5

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, S4 adds the intermediate.local wrapper when the arguments of the generic and the method differ in some way. I think it happens here because our method adds the dsn argument before the docs. (No need to change anything, I just thought you might want to know where this was coming from)

@simonpcouch simonpcouch requested a review from hadley April 9, 2024 16:54
Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

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

Looking good!

@@ -14,11 +14,10 @@ OdbcConnection <- function(
timeout = Inf,
dbms.name = NULL,
attributes = NULL,
.connection_string = NULL
.connection_string = NULL,
call = caller_env(2)
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, S4 adds the intermediate.local wrapper when the arguments of the generic and the method differ in some way. I think it happens here because our method adds the dsn argument before the docs. (No need to change anything, I just thought you might want to know where this was coming from)

@simonpcouch simonpcouch merged commit a55ef73 into main Apr 10, 2024
16 checks passed
@simonpcouch simonpcouch deleted the cnd-627 branch April 10, 2024 15:48
call = call
)
}
check_exclusive(table, view, .frame = call)
Copy link
Member

Choose a reason for hiding this comment

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

:chef kiss:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SUCH A SATISFYING DIFF

@mjkallen
Copy link

Is there a particular reason why some calls to warning() (like this one) were left in the code and not replaced with cli::cli_warn()? Or was your goal really to only cover errors?

I must say that I personally am not terribly happy with the switch to using cli_abort(), but I understand that the {odbc} package is an integral part of the database connections feature in the RStudio IDE and that it makes sense to follow the tidy design principle of being human centered. I just wish that it would be as easy to just call conditionMessage(x) on a condition object x returned by cli_abort (or any rlang_error object) to retrieve the original (i.e., unmodified) error message. Now, if you want to write these original error messages to a log file or display them in a Shiny application without all the extra bells and wistles added by cli_abort(), then you have to use a combination of rlang::cnd_message() and cli::ansi_strip() to get to the original message and even then I am unsure if this is guaranteed to return the original error/warning message...

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.

Use cli errors
3 participants