Skip to content

Commit

Permalink
Improve the error message when CRAN is closed
Browse files Browse the repository at this point in the history
Fixes #1958
  • Loading branch information
jimhester committed Dec 20, 2019
1 parent 221baee commit 03537c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# devtools 2.2.2

* `submit_cran()` now returns a more informative error when the CRAN submission
portal is down (#1958)

* `check()` gains a `vignettes` argument, to more easily disable checks for
vignettes (#2165).

Expand Down
27 changes: 27 additions & 0 deletions R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ build_cran <- function(pkg, args) {
built_path
}

extract_cran_msg <- function(msg) {
# Remove "CRAN package Submission" and "Submit package to CRAN"
msg <- gsub("CRAN package Submission|Submit package to CRAN", "", msg)

# remove all html tags
msg <- gsub("<[^>]+>", "", msg)

# remove tabs
msg <- gsub("\t+", "", msg)

# Remove extra newlines
msg <- gsub("\n+", "\n", msg)

msg
}

upload_cran <- function(pkg, built_path) {
pkg <- as.package(pkg)
maint <- maintainer(pkg)
Expand All @@ -303,6 +319,17 @@ upload_cran <- function(pkg, built_path) {
upload = "Upload package"
)
r <- httr::POST(cran_submission_url, body = body)

# If a 404 likely CRAN is closed for maintenance, try to get the message
if (httr::status_code(r) == 404) {
msg <- ""
try({
r2 <- httr::GET(sub("index2", "index", cran_submission_url))
msg <- extract_cran_msg(httr::content(r2, "text"))
})
stop("Submission failed:", msg, call. = FALSE)
}

httr::stop_for_status(r)
new_url <- httr::parse_url(r$url)

Expand Down

0 comments on commit 03537c6

Please sign in to comment.