tidyverse/googlesheets4

In elegant failure in `gs4_auth` when token file does not exist

Closed this issue · 2 comments

When a path is provided to gs4_auththat does not resolve to a file, the function automatically enters interactive mode. It would be nice if the function warned you or errored out if the file does not exist at that path.

Brief description of the problem:

function enters interactive mode without signaling to user that a file doesnt exist.

key_path <- "./auth/secret.json"
gs4_auth(path = key_path)

The answer to why this wish isn't particularly easy to grant is the same as in the linked gargle issue. I do note this as something that would be nice to do, but there are other priorities for attention over in gargle.

This runs counter to the design of gargle::token_fetch(). By design, it tries a series of auth methods, all wrapped in tryCatch(). Errors are to be expected and it's designed to soldier on and, eventually, ends up the interactive flow of last resort.

Basically, the fact that it "just works" for so many people means that there is a higher bar for folks using it in more advanced ways, i.e. with arguments.

So the frank answer is: make sure to pass a path to a file that actually exists 😅

Ah okay - thanks for the explanation. We will check for the file before passing the path to the gs4_auth

key_path <- "./auth/secret.json"

if(file.exists(key_path)){
    gs4_auth(path = key_path)
} else {
    stop("informative error message")
}