From e040cdff0eb0cdda610cbca1c730d020cbbfe5e8 Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Mon, 27 Mar 2023 14:33:21 -0700 Subject: [PATCH] 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. --- src/shared/Core/CommandContext.cs | 4 ++-- src/shared/Core/ISessionManager.cs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/Core/CommandContext.cs b/src/shared/Core/CommandContext.cs index 304bdb683..e2fe2a8ee 100644 --- a/src/shared/Core/CommandContext.cs +++ b/src/shared/Core/CommandContext.cs @@ -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); @@ -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); diff --git a/src/shared/Core/ISessionManager.cs b/src/shared/Core/ISessionManager.cs index 2569833f4..3804518e7 100644 --- a/src/shared/Core/ISessionManager.cs +++ b/src/shared/Core/ISessionManager.cs @@ -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; }