Skip to content

Commit de1ff8b

Browse files
authored
Ensure we init IEnvironment before SessionManager (#1167)
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.
2 parents 784e7c7 + e040cdf commit de1ff8b

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
@@ -119,8 +119,8 @@ public CommandContext()
119119
else if (PlatformUtils.IsMacOS())
120120
{
121121
FileSystem = new MacOSFileSystem();
122-
SessionManager = new MacOSSessionManager(Environment, FileSystem);
123122
Environment = new MacOSEnvironment(FileSystem);
123+
SessionManager = new MacOSSessionManager(Environment, FileSystem);
124124
ProcessManager = new ProcessManager(Trace2);
125125
Terminal = new MacOSTerminal(Trace, Trace2);
126126
string gitPath = GetGitPath(Environment, FileSystem, Trace);
@@ -136,8 +136,8 @@ public CommandContext()
136136
else if (PlatformUtils.IsLinux())
137137
{
138138
FileSystem = new LinuxFileSystem();
139-
SessionManager = new LinuxSessionManager(Environment, FileSystem);
140139
Environment = new PosixEnvironment(FileSystem);
140+
SessionManager = new LinuxSessionManager(Environment, FileSystem);
141141
ProcessManager = new ProcessManager(Trace2);
142142
Terminal = new LinuxTerminal(Trace, Trace2);
143143
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)