diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs
index d2d4601698..34a58a96cb 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs
@@ -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);
diff --git a/src/Microsoft.PowerShell.Commands.Utility/resources/ConvertMarkdownStrings.resx b/src/Microsoft.PowerShell.Commands.Utility/resources/ConvertMarkdownStrings.resx
index f9aacc5d6f..3b17b564f5 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/resources/ConvertMarkdownStrings.resx
+++ b/src/Microsoft.PowerShell.Commands.Utility/resources/ConvertMarkdownStrings.resx
@@ -126,4 +126,7 @@
Only FileSystem Provider paths are supported. The given path '{0}' is not supported.
+
+ The property {0} of the given object is null or empty.
+
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/MarkdownCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/MarkdownCmdlets.Tests.ps1
index 551eb5bf94..8764b340db 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/MarkdownCmdlets.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/MarkdownCmdlets.Tests.ps1
@@ -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 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'
+ }
+ }
}
}