Skip to content

Commit dd844f2

Browse files
authored
Merge pull request #3640 from AritraDey-Dev/fix/sipnet-download-check
Handle null status in SIPNET download script For DEMO 1 Notebook
2 parents 6c6f713 + fcd8056 commit dd844f2

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

documentation/tutorials/Demo_1_Basic_Run/download_sipnet.R

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,31 @@ download.file(
3939
Sys.chmod(dest_path, mode = "0755")
4040

4141
## Now we are run, lets just check that `sipnet -h` works
42-
43-
status <- suppressWarnings(
44-
system2(dest_path, "-h", stderr = TRUE, stdout = TRUE) |>
45-
attr("status")
42+
tryCatch(
43+
{
44+
# This block runs if system2 succeeds with exit code 0 (status attribute is NULL).
45+
# This is unexpected for `sipnet -h`, so we warn but assume it's OK.
46+
system2(dest_path, "-h", stderr = TRUE, stdout = TRUE)
47+
PEcAn.logger::logger.warn("SIPNET ran with exit code 0, but expected 1. Assuming installation is OK.")
48+
},
49+
warning = function(w) {
50+
# This block runs if system2 returns a non-zero exit code, which is expected.
51+
# We check the warning message for the expected status of 1.
52+
if (grepl("had status 1", w$message, fixed = TRUE)) {
53+
PEcAn.logger::logger.info("SIPNET has been installed!")
54+
} else {
55+
PEcAn.logger::logger.error("SIPNET ran but failed with an unexpected status.", "Details:", w$message)
56+
}
57+
},
58+
error = function(e) {
59+
# This block runs if system2 fails to execute the command at all.
60+
PEcAn.logger::logger.error(
61+
"SIPNET command failed to execute. The binary may be incompatible with your system.",
62+
"Details:", e$message
63+
)
64+
}
4665
)
4766

48-
if(status == 1){
49-
# 1 is expected for `sipnet -h`
50-
PEcAn.logger::logger.info("SIPNET has been installed!")
51-
} else {
52-
PEcAn.logger::logger.error("SIPNET installation has failed with status:", status)
53-
}
54-
5567
dir.create("dbfiles", showWarnings = FALSE)
5668
# Download demo .clim file
5769
climfile <- "https://gist.githubusercontent.com/dlebauer/8aea1146dc8f915e1dea7a7335d7ec24/raw/4cc127098b0b42a0d428fc7de580e17aafca4e8b/AMF_US-NR1_BASE_HH_23-5.2004-01-01.2004-12-31.clim"

0 commit comments

Comments
 (0)