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

R: Warn if error is too long to print properly #232

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/R/bridgestan.R
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ handle_error <- function(lib_name, err_msg, err_ptr, function_name) {
return(paste("Unknown error in", function_name))
} else {
.C("bs_free_error_msg_R", as.raw(err_ptr), PACKAGE = lib_name)
if (getOption("warning.length") < nchar(err_msg)) {
warning("BridgeStan error message too long to fully display. Consider increasing options(warning.length)")
}
return(err_msg)
}
}
Expand Down
11 changes: 8 additions & 3 deletions R/R/compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ get_bridgestan_path <- function() {
"environment variable, downloading version ", packageVersion("bridgestan"),
" to ", path))
get_bridgestan_src()
print("Done!")
})
num_files <- length(list.files(HOME_BRIDGESTAN))
if (num_files >= 5) {
warning(paste0("Found ", num_files, " different versions of BridgeStan in ",
HOME_BRIDGESTAN, ". Consider deleting old versions to save space."))
}
print("Done!")
}

return(path)
Expand Down Expand Up @@ -101,8 +101,13 @@ compile_model <- function(stan_file, stanc_args = NULL, make_args = NULL) {
})
res_attrs <- attributes(res)
if ("status" %in% names(res_attrs) && res_attrs$status != 0) {
stop(paste0("Compilation failed with error code ", res_attrs$status, "\noutput:\n",
paste(res, collapse = "\n")))
error_msg <- paste0("Compilation failed with error code ", res_attrs$status,
"\noutput:\n", paste(res, collapse = "\n"))

if (getOption("warning.length") < nchar(error_msg)) {
warning("BridgeStan error message too long to fully display. Consider increasing options(warning.length)")
}
stop(error_msg)
}

return(output)
Expand Down
Loading