R と rmongodb を使用して、MongoDB NoSQL データベースからデータを抽出しています。try()
悪いデータから発生する問題をキャッチするロジックを入れました。ほとんどの場合try()
、エラーをキャッチして、不正なデータ オブジェクトをスキップします。ただし、時々、それをキャッチするのに「失敗」し、プログラムが停止します。以下は、時々機能するが、たまに失敗するコードですif(inherits(...))
。関数iter1
を呼び出す前に、(私が知っている限り)有効であることを確認するためにチェックを入れました。mongo.son.iterator.value()
実際、try()
プログラム全体で以下のような呼び出しで使用しました。前に試しtryCatch
たことがありますが、結果は同じだったと思います。どんな助けでも大歓迎です!
v2 <- try(mongo.bson.iterator.value(iter1))
if(inherits(v2, "try-error")) {
cat("mongo.bson.iterator.VALUE(iter1) ERROR ^^^^^^ , next!")
Sys.sleep(10)
next;
}
出力:
ItemName = VH013269
before value(iter1)
type of iter1: integer
*** caught segfault ***
address 0x7402cd5, cause 'memory not mapped'
Traceback:
1: .Call(".mongo.bson.iterator.value", iter)
2: mongo.bson.iterator.value(iter1)
3: doTryCatch(return(expr), name, parentenv, handler)
4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch(expr, error = function (e) {
call <- conditionCall(e)
if (!is.null(call)) {
if (identical(call[[1L]], quote(doTryCatch)))
call <- sys.call(-4L)
dcall <- deparse(call)[1L]
prefix <- paste("Error in", dcall, ": ")
LONG <- 75L
msg <- conditionMessage(e)
sm <- strsplit(msg, "\n")[[1L]]
w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")
if (is.na(w))
w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b")
if (w > LONG)
prefix <- paste0(prefix, "\n ")
}
else prefix <- "Error : "
msg <- paste0(prefix, conditionMessage(e), "\n")
.Internal(seterrmessage(msg[1L]))
if (!silent && identical(getOption("show.error.messages"),
TRUE)) {
cat(msg, file = stderr())
.Internal(printDeferredWarnings())
}
invisible(structure(msg, class = "try-error", condition = e))
})
7: try(mongo.bson.iterator.value(iter1))
8: eval(expr, envir, enclos)
9: eval(ei, envir)
10: withVisible(eval(ei, envir))
11: source("parcc_mci_v5.R")
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: