标签: error-handling

如何在 R 中打印实际的错误消息

我试图返回 R 函数中的任何实际错误消息,并向其发送电子邮件以通知用户,但它仅打印 R 参数中的自定义消息。有什么办法可以在电子邮件中发送实际的错误消息吗?

以下是我迄今为止编写的虚拟脚本:

mailme <- function(message){
  #function to send email
}

b<-function(){
  r <- NULL
  attempt <- 1
  while( is.null(r) && attempt <= 3 ) {
    attempt <- attempt + 1
    try({
      x<-2+3
      prin(x)})
  }
  stop("The error message")
}

a <- tryCatch({
  b()
}, error = function(e){
  mailme(e$message)
})
  
Run Code Online (Sandbox Code Playgroud)

实际返回的错误信息是

Error in prin(x) : could not find function "prin"
Run Code Online (Sandbox Code Playgroud)

但是我在电子邮件中收到的错误消息是

The error message  #from the stop used in function b
Run Code Online (Sandbox Code Playgroud)

如何在停靠点内调用实际的错误消息?

error-handling r try-catch

0
推荐指数
1
解决办法
1525
查看次数

MongoEngine fieldDoesNotExist 错误但实际上是

我有一堂课:

\n
class POI(Document):\n    location = PointField(required=True)\n    name = StringField(default='')\n    generate_by = IntField(required=True)\n    status = StringField(default='Active')\n    colle\xd1\x81ted_by = IntField()\n    time_created = DateTimeField(default=datetime.datetime.now)\n
Run Code Online (Sandbox Code Playgroud)\n

当我尝试插入时

\n
POI(location=[55.430212, 30.521000], generate_by=1241254, name="Sample", collected_by=None)\n
Run Code Online (Sandbox Code Playgroud)\n

发生错误

\n
mongoengine.errors.FieldDoesNotExist: The fields "{'collected_by'}" do not exist on the document "POI"\n
Run Code Online (Sandbox Code Playgroud)\n

怎么了?

\n

python error-handling mongodb mongoengine

0
推荐指数
1
解决办法
1198
查看次数

当未找到人脸时,如何处理 deepFace.analyze() 中的错误?

img=cv2.imread(face.jpg)
predictions= DeepFace.analyze(img)
Run Code Online (Sandbox Code Playgroud)

Error: Face could not be detected. Please confirm that the picture is a face photo or consider to set enforce_detection param to False.

设置enforce_detectionFalse会导致即使图像中没有面部,它也会读取情绪

我们如何处理这个错误,让它告诉我们没有人脸?

python error-handling face-detection deepface

0
推荐指数
1
解决办法
1万
查看次数

错误字符串在多大程度上保证不改变?

我对 Golang 的主要问题之一是错误处理基本上是对字符串的检查(我很乐意出错,不要犹豫:))

在下面的示例中,我尝试创建一个目录,但根据问题的类型会有不同的行为。具体来说,如果目录存在,我将直接通过。

package main

import (
    "fmt"
    "os"
)

func main() {
    err := os.Mkdir("test", 0644)
    if err != nil {
        fmt.Printf("error: %v", err)
        if err.Error() == "mkdir test: Cannot create a file when that file already exists" {
            fmt.Printf("the dir already exists")
        } else {
            panic(err)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

它不起作用,不会记录重复的尝试。为什么?啊,糟糕,我忘记了字符串末尾的点mkdir test: Cannot create a file when that file already exists

我觉得依赖错误字符串是脆弱的,而不是像err.ErrorType().DirectoryExists()检查这样的东西(例如有时存在net)。

我的问题:我可以在多大程度上相信错误字符串不会改变?(换句话说,mkdir test: Cannot create a file when that …

error-handling go

0
推荐指数
1
解决办法
103
查看次数

在 `try` 内发生错误,未由 `catch` 处理

我希望块内抛出的特定错误try不被处理catch(err)

例子:

const someFunc = async () => {
  ...
  try {
    ...
    // This error should not be handled by the catch and go straight to the middleware
    throw {
      status: 404,
      message: "Not Found",
    };
  } catch (error) {
    throw {
      status: 500,
      message: "Something went wrong",
      reason: error,
    };
  }
};
Run Code Online (Sandbox Code Playgroud)

之后中间件处理错误。

export const errorHandler: ErrorRequestHandler = (err, req, res, next) => {
  const { status = 500, message, reason } = err;
  res.status(status).json({ …
Run Code Online (Sandbox Code Playgroud)

javascript error-handling express typescript

0
推荐指数
1
解决办法
969
查看次数

我如何访问 golang 中的错误单个属性

!! 我是新来的!

我正在使用 datasync API 来启动任务执行,没有任何问题。我正在努力处理返回的错误结构,我想访问各个元素,但我似乎无法做到这一点。

例如,在以下错误中我希望能够访问Message_的内容

2022/03/19 09:33:48 Sync called : 
InvalidRequestException: Unable to queue the task execution for task task-xxxxxxxxxxxx. The task already has another task execution exec-030b4a31dc2e33641 currently running or queued with identical Include and Exclude filter patterns. Please provide unique Include and Exclude filter patterns for the new task execution and try again.
{
  RespMetadata: {
    StatusCode: 400,
    RequestID: "xxxxxxxxxxxxxxxxxxxxx"
  },
  ErrorCode: "DedupeFailed",
  Message_: "Unable to queue the task execution for task task-xxxxxxxxxx. The task …
Run Code Online (Sandbox Code Playgroud)

error-handling go amazon-web-services aws-datasync

0
推荐指数
1
解决办法
631
查看次数

如何简化重复的 try- except 块

我有下面的代码需要检查是否找到任何对象的可见属性。try- except 块中的每个首字母缩略词函数如果找到则返回一个对象引用,每个都有自己的visible属性。如果未找到任何首字母缩略词对象,我的程序将因调用(例如)DR() 而引发 LookUpError。我觉得必须有一种方法来简化这段代码,这样我就不必指定所有这些单独的 try- except 块,但我无法考虑如何有效地做到这一点。

    def detect_planning_workflow_page():
        
        workflow = None
        
        try:
            if DR().visible:
                workflow = "DR"
        except LookupError:
            pass
        
        try:
            if LL().visible:
                workflow = "LL"
        except LookupError:
            pass
        
        try:
            if AZ().visible:
                workflow = "AZ"
        except LookupError:
            pass
        
        try:
            if SP().visible:
                workflow = "SP"
        except LookupError:
            pass
        
        try:
            if MS().visible:
                workflow = "Define Region"
        except LookupError:
            pass
        
        return workflow

Run Code Online (Sandbox Code Playgroud)

python lookup error-handling try-except

0
推荐指数
1
解决办法
34
查看次数

正确处理异常

我的理解是,在现代 C++ 中,最好使用throw而不是返回错误代码。也就是说,如果我有一些功能:

void MyFunction(int foo, double bar){
    // Do some stuff....

    if (exception_criteria_met){
        throw "Call to MyFunction with inputs" << foo << " and " << bar << " failed because ...";
    }
};
Run Code Online (Sandbox Code Playgroud)

这是否意味着,为了正确处理这个问题,那么在所有调用 的函数中MyFunction,我必须实现如下所示的内容:

void MyOuterFunction(int foo){
    // Do some stuff...

    try {
        MyFunction(foo, bar);
    } catch (const char * exception_message) {
        throw "Call to MyOuterFunction with inputs " << foo << " failed because call to MyFunction with ....";
    };
Run Code Online (Sandbox Code Playgroud)

那么这是否意味着我必须对调用该函数调用堆栈的所有函数一直执行相同类型的错误处理? …

c++ error-handling try-catch throw

0
推荐指数
1
解决办法
205
查看次数

在基因过滤器库中找不到数据集“eset”

我在练习R语言练习时,遇到一道题,要求我访问“ eset”库中的“ genefilter”数据集;

\n
> library(genefilter)\n> data(eset)\n
Run Code Online (Sandbox Code Playgroud)\n

但我总是收到以下错误;

\n
In data(eset) : data set \xe2\x80\x98eset\xe2\x80\x99 not found\n
Run Code Online (Sandbox Code Playgroud)\n

我遇到了同样的错误;

\n
>library(globaltest);\n>data(exampleX);\n>data(exampleY);\n
Run Code Online (Sandbox Code Playgroud)\n

有人可以向我解释一下我在这里做错了什么吗?

\n

我搜索了所有BiocManager文档,但找不到有用的答案。

\n

error-handling r

0
推荐指数
1
解决办法
54
查看次数

这些图像无法按照教程使用 i18n 在 nextjs 中制作我的页面,有人可以帮助我吗?

一切都很好,翻译了 nextjs13.4、tailwindcss 和 i18n 中的所有内容,我没有使用打字稿,但我的图像尽管位于公共文件夹中,却无法加载到任何地方。

我在控制台中收到错误: GET http://localhost:3000/_next/image?url=%2Fimagentest.jpg&w=128&q=75 400 (错误请求)

指南:https://locize.com/blog/next-13-app-dir-i18n/

我希望你能帮助我如何修复此代码错误

error-handling public nextjs-image next.js13

0
推荐指数
1
解决办法
748
查看次数