Skip to content

Commit a447dee

Browse files
committed
Make sure the Runspace is available and throw otherwise
1 parent fd2fcec commit a447dee

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

shell/AIShell.Integration/AIShell.psm1

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ if ($null -eq $module -or $module.Version -lt [version]"2.4.2") {
77
throw "The PSReadLine v2.4.2-beta2 or higher is required for the AIShell module to work properly."
88
}
99

10+
$runspace = $Host.Runspace
11+
if ($null -eq $runspace) {
12+
throw "Failed to import the module because '`$Host.Runspace' unexpectedly returns null.`nThe host details:`n$($Host | Out-String -Width 120)"
13+
}
14+
1015
## Create the channel singleton when loading the module.
11-
$null = [AIShell.Integration.Channel]::CreateSingleton($host.Runspace, [Microsoft.PowerShell.PSConsoleReadLine])
16+
$null = [AIShell.Integration.Channel]::CreateSingleton($runspace, [Microsoft.PowerShell.PSConsoleReadLine])

shell/AIShell.Integration/Channel.cs

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class Channel : IDisposable
3131

3232
private Channel(Runspace runspace, Type psConsoleReadLineType)
3333
{
34+
ArgumentNullException.ThrowIfNull(runspace);
35+
ArgumentNullException.ThrowIfNull(psConsoleReadLineType);
36+
3437
_runspace = runspace;
3538
_psrlType = psConsoleReadLineType;
3639
_connSetupWaitHandler = new ManualResetEvent(false);

0 commit comments

Comments
 (0)