Added missing error messages

This commit is contained in:
Aditya Patwardhan 2018-07-11 15:39:36 -07:00
parent 7bf1604f97
commit a78d006ac1
3 changed files with 25 additions and 10 deletions

View file

@ -8,6 +8,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Internal;
using Microsoft.PowerShell.MarkdownRender;
namespace Microsoft.PowerShell.Commands
@ -61,8 +62,9 @@ namespace Microsoft.PowerShell.Commands
if (markdownInfo == null)
{
string errorMessage = StringUtil.Format(ConvertMarkdownStrings.InvalidInputObjectType, inpObj.GetType());
var errorRecord = new ErrorRecord(
new ArgumentException(),
new ArgumentException(errorMessage),
"InvalidInputObject",
ErrorCategory.InvalidArgument,
InputObject);
@ -90,21 +92,15 @@ namespace Microsoft.PowerShell.Commands
}
ProcessStartInfo startInfo = new ProcessStartInfo();
#if UNIX
startInfo.FileName = Platform.IsLinux ? "xdg-open" : /* macOS */ "open";
startInfo.Arguments = tmpFilePath;
#else
startInfo.FileName = tmpFilePath;
startInfo.UseShellExecute = true;
#endif
Process.Start(startInfo);
}
else
{
string errorMessage = StringUtil.Format(ConvertMarkdownStrings.MarkdownInfoInvalid, "Html");
var errorRecord = new ErrorRecord(
new InvalidDataException(),
new InvalidDataException(errorMessage),
"HtmlIsNullOrEmpty",
ErrorCategory.InvalidData,
html);
@ -131,8 +127,9 @@ namespace Microsoft.PowerShell.Commands
}
else
{
string errorMessage = StringUtil.Format(ConvertMarkdownStrings.MarkdownInfoInvalid, "VT100EncodedString");
var errorRecord = new ErrorRecord(
new InvalidDataException(),
new InvalidDataException(errorMessage),
"VT100EncodedStringIsNullOrEmpty",
ErrorCategory.InvalidData,
vt100String);

View file

@ -126,4 +126,7 @@
<data name="FileSystemPathsOnly" xml:space="preserve">
<value>Only FileSystem Provider paths are supported. The given path '{0}' is not supported.</value>
</data>
<data name="MarkdownInfoInvalid" xml:space="preserve">
<value>The property {0} of the given object is null or empty.</value>
</data>
</root>

View file

@ -316,5 +316,20 @@ bool function()`n{`n}
$result = $mdText | ConvertFrom-Markdown | Show-Markdown -UseBrowser
$result | Should -BeExactly $expectedString
}
It "Gets an error if the input object is missing the <propertyname> property." -TestCases @(@{propertyname = 'Html'}, @{propertyname = 'VT100EncodedString'}) {
param($propertyname)
$markdownInfo = [Microsoft.PowerShell.MarkdownRender.MarkdownInfo]::new()
if($propertyname -eq 'VT100EncodedString')
{
{ Show-Markdown -InputObject $markdownInfo -ErrorAction Stop } | Should -Throw -ErrorId 'VT100EncodedStringIsNullOrEmpty,Microsoft.PowerShell.Commands.ShowMarkdownCommand'
}
else
{
{ Show-Markdown -UseBrowser -InputObject $markdownInfo -ErrorAction Stop } | Should -Throw -ErrorId 'HtmlIsNullOrEmpty,Microsoft.PowerShell.Commands.ShowMarkdownCommand'
}
}
}
}