首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >psake中的错误报告

psake中的错误报告
EN

Stack Overflow用户
提问于 2015-04-28 18:14:52
回答 1查看 495关注 0票数 3

如何通知我普米卡任务列表中任何任务中的任何错误。?

在通知处理程序中,我希望显示任务失败的窗口通知。但是psake吞下了异常并将其写入控制台。

更新:这里的是Psake脚本中的代码,它吞噬了错误

代码语言:javascript
复制
 # if we are running in a nested scope (i.e. running a psake script from a psake script) then we need to re-throw the exception
        # so that the parent script will fail otherwise the parent script will report a successful build 
        $inNestedScope = ($psake.context.count -gt 1)
        if ( $inNestedScope ) {
            throw $_
        } else {
            if (!$psake.run_by_psake_build_tester) {
                WriteColoredOutput $error_message -foregroundcolor Red
            }
        }
EN

回答 1

Stack Overflow用户

发布于 2015-04-29 12:13:09

这就是我处理这个问题的方法。首先,在这个异常吞咽代码之前的某个地方,创建一个名为$errors的新对象,它是一个ArrayList类型(对于构建消息集合非常有用和快速)。

代码语言:javascript
复制
$errors = New-Object System.Collections.ArrayList
# if we are running in a nested scope (i.e. running a psake script from a psake script) then we need to re-throw the exception
        # so that the parent script will fail otherwise the parent script will report a successful build 
        $inNestedScope = ($psake.context.count -gt 1)
        if ( $inNestedScope ) {
            throw $_
        } else {
            if (!$psake.run_by_psake_build_tester) {
                WriteColoredOutput $error_message -foregroundcolor Red
                $errors.Add($error[0])
            }
        }

        <#.the rest of your code...#>

       if ($errors.Count -ne 0){
        Write-Warning 'A number of errors were encountered during the processing of this task, please review them, below'
        $errors

       }

这是一个非常简单的方法,可能会完成这项工作。我们仍然允许将错误写到屏幕上,但也收集它们以显示脚本中的其他部分。

如果这个方法不是你想要的,请告诉我?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29926946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档