-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rethrow errors from native_cmd
- Loading branch information
Showing
11 changed files
with
189 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: condathis | ||
Title: Run Any CLI Tool on a 'Conda' Environment | ||
Version: 0.0.7.9010 | ||
Version: 0.0.7.9011 | ||
Authors@R: c( | ||
person("Lucio", "Queiroz", , "[email protected]", role = c("aut", "cre", "cph"), | ||
comment = c(ORCID = "0000-0002-6090-1834")), | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' @keywords internal | ||
#' @noRd | ||
rethrow_error_cmd <- function(expr, env = parent.frame()) { | ||
code <- base::substitute(expr = expr) | ||
err_cnd <- rlang::catch_cnd( | ||
expr = { | ||
px_res <- rlang::eval_bare(expr = code, env = env) | ||
}, | ||
classes = c("system_command_status_error", "rlib_error_3_0", "c_error") | ||
) | ||
|
||
if (isFALSE(is.null(err_cnd))) { | ||
additional_lines <- NULL | ||
if (isTRUE("stderr" %in% names(err_cnd))) { | ||
additional_lines <- stringr::str_split( | ||
string = stringr::str_trim(err_cnd[["stderr"]]), | ||
pattern = stringr::regex("\\R"), | ||
simplify = FALSE | ||
)[[1]] | ||
} | ||
|
||
status_code <- NULL | ||
if (isFALSE("status" %in% names(err_cnd))) { | ||
status_code <- "127" | ||
additional_lines <- c("micromamba: command not found", additional_lines) | ||
} else { | ||
status_code <- err_cnd[["status"]] | ||
} | ||
|
||
env[["status_code"]] <- status_code | ||
cli::cli_abort( | ||
message = c( | ||
additional_lines | ||
), | ||
class = "condathis_cmd_status_error", | ||
.envir = env | ||
) | ||
} | ||
|
||
return(px_res) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#' @keywords internal | ||
#' @noRd | ||
rethrow_error_run <- function(expr, env = parent.frame()) { | ||
code <- base::substitute(expr = expr) | ||
err_cnd <- rlang::catch_cnd( | ||
expr = { | ||
px_res <- rlang::eval_bare(expr = code, env = env) | ||
}, | ||
classes = c("system_command_status_error", "rlib_error_3_0", "c_error") | ||
) | ||
|
||
if (isFALSE(is.null(err_cnd))) { | ||
additional_lines <- NULL | ||
if (isTRUE("stderr" %in% names(err_cnd))) { | ||
additional_lines <- stringr::str_split( | ||
string = stringr::str_trim(err_cnd[["stderr"]]), | ||
pattern = stringr::regex("\\R"), | ||
simplify = FALSE | ||
)[[1]] | ||
} | ||
|
||
status_code <- NULL | ||
if (isFALSE("status" %in% names(err_cnd))) { | ||
status_code <- "127" | ||
additional_lines <- c("{cmd}: command not found", additional_lines) | ||
} else { | ||
status_code <- err_cnd[["status"]] | ||
} | ||
|
||
env[["status_code"]] <- status_code | ||
cli::cli_abort( | ||
message = c( | ||
`x` = "System command {.field {cmd}} failed", | ||
`!` = "Status code: {status_code}", | ||
additional_lines | ||
), | ||
class = "condathis_run_status_error", | ||
.envir = env | ||
) | ||
} | ||
|
||
return(px_res) | ||
} |
This file contains 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
This file contains 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
This file contains 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