Skip to content

Commit e040cdf

Browse files
committed
commandcontext: ensure we init IEnvironment before SessionManager
Ensure we have an instance of IEnvironment before we pass it to the SessionManager contructor. Also add some null guards to catch this problem earlier in the future.
1 parent d1b9b8b commit e040cdf

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/shared/Core/CommandContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public CommandContext()
118118
else if (PlatformUtils.IsMacOS())
119119
{
120120
FileSystem = new MacOSFileSystem();
121-
SessionManager = new MacOSSessionManager(Environment, FileSystem);
122121
Environment = new MacOSEnvironment(FileSystem);
122+
SessionManager = new MacOSSessionManager(Environment, FileSystem);
123123
ProcessManager = new ProcessManager(Trace2);
124124
Terminal = new MacOSTerminal(Trace);
125125
string gitPath = GetGitPath(Environment, FileSystem, Trace);
@@ -134,8 +134,8 @@ public CommandContext()
134134
else if (PlatformUtils.IsLinux())
135135
{
136136
FileSystem = new LinuxFileSystem();
137-
SessionManager = new LinuxSessionManager(Environment, FileSystem);
138137
Environment = new PosixEnvironment(FileSystem);
138+
SessionManager = new LinuxSessionManager(Environment, FileSystem);
139139
ProcessManager = new ProcessManager(Trace2);
140140
Terminal = new LinuxTerminal(Trace);
141141
string gitPath = GetGitPath(Environment, FileSystem, Trace);

src/shared/Core/ISessionManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public abstract class SessionManager : ISessionManager
2222

2323
protected SessionManager(IEnvironment env, IFileSystem fs)
2424
{
25+
EnsureArgument.NotNull(env, nameof(env));
26+
EnsureArgument.NotNull(fs, nameof(fs));
27+
2528
Environment = env;
2629
FileSystem = fs;
2730
}

0 commit comments

Comments
 (0)