Skip to content

Commit

Permalink
fix: Quieter default non-interactive error handler
Browse files Browse the repository at this point in the history
* When an error is thrown by `ArgumentParser()$parse_args()` and `interactive()` is `FALSE`
  and `getOption("error")` is `NULL` then
  we now use a quieter default error handler that doesn't output a trailing "Execution halted".

follow-up on #40
  • Loading branch information
trevorld committed Jul 18, 2022
1 parent 0d3aa88 commit 1a20610
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: argparse
Type: Package
Title: Command Line Optional and Positional Argument Parser
Version: 2.1.6
Version: 2.1.7-0
Authors@R: c(person("Trevor L", "Davis", role=c("aut", "cre"),
email="trevor.l.davis@gmail.com",
comment = c(ORCID = "0000-0001-6341-4639")),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
argparse 2.1.7
==============

* When an error is thrown by `ArgumentParser()$parse_args()` and `interactive()` is `FALSE`
and `getOption("error")` is `NULL` then
we now use a quieter default error handler that doesn't output a trailing "Execution halted".

argparse 2.1.6
==============

Expand Down
7 changes: 6 additions & 1 deletion R/argparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ find_python_cmd <- function(python_cmd = NULL) {
python_cmd
}

quieter_error_handler <- function(e) {
quit('no', status = 1, runLast = FALSE)
}

pa_stop <- function(message, r_note) {
msg <- paste(c(r_note, message), collapse = "\n")
cnd <- errorCondition(msg,
Expand All @@ -368,7 +372,8 @@ pa_stop <- function(message, r_note) {
} else {
signalCondition(cnd)
cat(message, sep = "\n", file = stderr())
opt <- options(show.error.messages = FALSE)
opt <- options(error = getOption("error", quieter_error_handler),
show.error.messages = FALSE)
on.exit(options(opt))
stop(cnd)
}
Expand Down

0 comments on commit 1a20610

Please sign in to comment.