Skip to content

Commit

Permalink
improve two error messages:
Browse files Browse the repository at this point in the history
1. for read.oce() on an empty file
2. for plot,echosounder-method() on an unrecognized 'which' value
  • Loading branch information
dankelley committed Dec 18, 2019
1 parent 2f9e2de commit 4e59dc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 9 additions & 8 deletions R/echosounder.R
Original file line number Diff line number Diff line change
Expand Up @@ -578,16 +578,10 @@ setMethod(f="plot",
else
lay <- layout(matrix(1:2, nrow=2, byrow=TRUE))
}
oceDebug(debug, "which:", which, "\n")
oceDebug(debug, "which before converting to numbers: c(", paste(which, collapse=","), ")\n")
whichOrig <- which
which <- oce.pmatch(which, list("zt image"=1, "zx image"=2, map=3))
if (!(which %in% 1:3)) {
if (is.character(whichOrig))
stop("In plot,echosounder-method : unknown value of which (\"", whichOrig, "\"); try 1, 2 or 3, or, equivalently, \"zt image\", \"zx image\" or \"map\"", call.=FALSE)
else
stop("In plot,echosounder-method : unknown value of which (", whichOrig, "); try 1, 2 or 3, or, equivalently, \"zt image\", \"zx image\" or \"map\"", call.=FALSE)
}
oceDebug(debug, "which:", which, "\n")
oceDebug(debug, "which after converting to numbers: c(", paste(which, collapse=","), ")\n")
for (w in seq_along(which)) {
oceDebug(debug, "this which:", which[w], "\n")
if (which[w] == 1) {
Expand Down Expand Up @@ -757,6 +751,13 @@ setMethod(f="plot",
}
}
lines(lon, lat, col=if (!is.function(col)) col else "black", lwd=lwd)
} else {
stop("In plot,echosounder-method : unknown value of which (",
if (is.character(whichOrig[w])) {
paste("\"", whichOrig[w], "\"", sep="")
} else {
whichOrig[w]
}, "); try 1, 2 or 3, or, equivalently, \"zt image\", \"zx image\" or \"map\"", call.=FALSE)
}
}
oceDebug(debug, "} # plot.echosounder()\n", unindent=1, style="bold")
Expand Down
4 changes: 3 additions & 1 deletion R/oce.R
Original file line number Diff line number Diff line change
Expand Up @@ -2024,8 +2024,10 @@ read.oce <- function(file, ...)
{
if (missing(file))
stop("must supply 'file'")
if (is.character(file) && "http://" != substr(file, 1, 7) && !file.exists(file))
stop("In read.oce() : cannot open '", file, "' because there is no such file or directory", call.=FALSE)
if (is.character(file) && "http://" != substr(file, 1, 7) && 0 == file.info(file)$size)
stop("empty file (read.oce)")
stop("empty file")
dots <- list(...)
debug <- if ("debug" %in% names(dots)) dots$debug else 0
type <- oceMagic(file, debug=debug-1)
Expand Down

0 comments on commit 4e59dc0

Please sign in to comment.