This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1726 from erwinvanhunen/dev
Added Get-PnPException cmdlet
- Loading branch information
Showing
8 changed files
with
203 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using SharePointPnP.PowerShell.CmdletHelpAttributes; | ||
using SharePointPnP.PowerShell.Commands.Model; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
|
||
namespace SharePointPnP.PowerShell.Commands.Base | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "PnPException")] | ||
[CmdletHelp("Returns the last exception that occured", | ||
@"Returns the last exception which can be used while debugging PnP Cmdlets", | ||
Category = CmdletHelpCategory.Base)] | ||
[CmdletExample( | ||
Code = @"PS:> Get-PnPException", | ||
Remarks = "Returns the last exception", | ||
SortOrder = 1)] | ||
[CmdletExample( | ||
Code = @"PS:> Get-PnPException -All", | ||
Remarks = "Returns all exceptions that occurred", | ||
SortOrder = 2)] | ||
public class GetException : PSCmdlet | ||
{ | ||
[Parameter(Mandatory = false, HelpMessage = "Show all exceptions")] | ||
public SwitchParameter All; | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
var exceptions = (ArrayList)this.SessionState.PSVariable.Get("error").Value; | ||
if (exceptions.Count > 0) | ||
{ | ||
var output = new List<PnPException>(); | ||
if (All.IsPresent) | ||
{ | ||
foreach (ErrorRecord exception in exceptions) | ||
{ | ||
output.Add(new PnPException() { Message = exception.Exception.Message, Stacktrace = exception.Exception.StackTrace, ScriptLineNumber = exception.InvocationInfo.ScriptLineNumber, InvocationInfo = exception.InvocationInfo }); | ||
} | ||
} | ||
else | ||
{ | ||
var exception = (ErrorRecord)exceptions[0]; | ||
output.Add(new PnPException() { Message = exception.Exception.Message, Stacktrace = exception.Exception.StackTrace, ScriptLineNumber = exception.InvocationInfo.ScriptLineNumber, InvocationInfo = exception.InvocationInfo }); | ||
} | ||
WriteObject(output, true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SharePointPnP.PowerShell.Commands.Model | ||
{ | ||
public class PnPException | ||
{ | ||
public string Message; | ||
public string Stacktrace; | ||
public int ScriptLineNumber; | ||
public InvocationInfo InvocationInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters