Skip to content

Commit

Permalink
commandcontext: ensure we init IEnvironment before SessionManager
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mjcheetham committed Mar 27, 2023
1 parent d1b9b8b commit e040cdf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/shared/Core/CommandContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public CommandContext()
else if (PlatformUtils.IsMacOS())
{
FileSystem = new MacOSFileSystem();
SessionManager = new MacOSSessionManager(Environment, FileSystem);
Environment = new MacOSEnvironment(FileSystem);
SessionManager = new MacOSSessionManager(Environment, FileSystem);
ProcessManager = new ProcessManager(Trace2);
Terminal = new MacOSTerminal(Trace);
string gitPath = GetGitPath(Environment, FileSystem, Trace);
Expand All @@ -134,8 +134,8 @@ public CommandContext()
else if (PlatformUtils.IsLinux())
{
FileSystem = new LinuxFileSystem();
SessionManager = new LinuxSessionManager(Environment, FileSystem);
Environment = new PosixEnvironment(FileSystem);
SessionManager = new LinuxSessionManager(Environment, FileSystem);
ProcessManager = new ProcessManager(Trace2);
Terminal = new LinuxTerminal(Trace);
string gitPath = GetGitPath(Environment, FileSystem, Trace);
Expand Down
3 changes: 3 additions & 0 deletions src/shared/Core/ISessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public abstract class SessionManager : ISessionManager

protected SessionManager(IEnvironment env, IFileSystem fs)
{
EnsureArgument.NotNull(env, nameof(env));
EnsureArgument.NotNull(fs, nameof(fs));

Environment = env;
FileSystem = fs;
}
Expand Down

0 comments on commit e040cdf

Please sign in to comment.