1

我在sample.ts(打字稿)中有以下代码,其中 exe 始终返回 0(成功)、1(失败)或 2(未知错误)的退出代码。我希望validateFunc调用正确返回退出代码并进入下一行,但它会转到非零退出代码的 catch 块。知道是什么导致了这种行为吗?

try

{

...{some code}

 let exitCode = await validateFunc("sample1", "sample2");

if(exitcode!=0)
{
  // expecting toland here when tool returns non-zero exit code
}

..{some code here}

}
catch (error)

{

 // Above call to validateFunc lands here for non-zero exit codes

}

export async function validateFunc(param1: string, param2: string) {

   
      {some code here}

    return await tl.exec(`${validationToolRoot}\\<Exename>`, validationArgs);
}
4

1 回答 1

0

检查$ErrorActionPreference的值。如果不是 Stop,catch 将不会运行。

在 try-block 之前尝试 add $ErrorActionPreference = "Stop",它应该正确捕获错误。

有关更多详细信息,请查看此错误:Powershell tr​​y block not working on VSTS build

于 2020-11-04T07:54:59.097 回答