Browse Source

Show line being executed in the console window when a PowerShell script has a runtime error.

pull/15/head
Matt Ward 15 years ago
parent
commit
adeeb6ceb9
  1. 1
      src/AddIns/Misc/PackageManagement/Cmdlets/Project/PackageManagement.Cmdlets.csproj
  2. 8
      src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/PackageManagementCmdlet.cs
  3. 46
      src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/RuntimeExceptionErrorMessage.cs

1
src/AddIns/Misc/PackageManagement/Cmdlets/Project/PackageManagement.Cmdlets.csproj

@ -49,6 +49,7 @@ @@ -49,6 +49,7 @@
<Compile Include="Src\InstallPackageCmdlet.cs" />
<Compile Include="Src\ITerminatingCmdlet.cs" />
<Compile Include="Src\PackageManagementCmdlet.cs" />
<Compile Include="Src\RuntimeExceptionErrorMessage.cs" />
<Compile Include="Src\UninstallPackageCmdlet.cs" />
<Compile Include="Src\UpdatePackageCmdlet.cs" />
</ItemGroup>

8
src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/PackageManagementCmdlet.cs

@ -90,7 +90,13 @@ namespace ICSharpCode.PackageManagement.Cmdlets @@ -90,7 +90,13 @@ namespace ICSharpCode.PackageManagement.Cmdlets
public void InvokeScript(string script)
{
InvokeCommand.InvokeScript(script);
try {
InvokeCommand.InvokeScript(script);
} catch (RuntimeException ex) {
var errorMessage = new RuntimeExceptionErrorMessage(ex);
WriteWarning(errorMessage.ToString());
throw;
}
}
}
}

46
src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/RuntimeExceptionErrorMessage.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Management.Automation;
using System.Text;
namespace ICSharpCode.PackageManagement.Cmdlets
{
public class RuntimeExceptionErrorMessage
{
StringBuilder message = new StringBuilder();
public RuntimeExceptionErrorMessage(RuntimeException ex)
{
CreateErrorMessage(ex);
}
void CreateErrorMessage(RuntimeException ex)
{
message.AppendLine(ex.Message);
AppendErrorRecord(ex.ErrorRecord);
}
void AppendErrorRecord(ErrorRecord errorRecord)
{
if (errorRecord != null) {
AppendInvocationInfo(errorRecord.InvocationInfo);
}
}
void AppendInvocationInfo(InvocationInfo invocationInfo)
{
if (invocationInfo != null) {
message.AppendLine(invocationInfo.PositionMessage);
message.AppendLine("Script Line: " + invocationInfo.ScriptLineNumber);
message.AppendLine("Script Name: " + invocationInfo.ScriptName);
}
}
public override string ToString()
{
return message.ToString();
}
}
}
Loading…
Cancel
Save