diff --git a/src/components/tbc.core/Socket/Abstractions/IRemoteEndpoint.cs b/src/components/tbc.core/Socket/Abstractions/IRemoteEndpoint.cs index ba83343..0157ad0 100644 --- a/src/components/tbc.core/Socket/Abstractions/IRemoteEndpoint.cs +++ b/src/components/tbc.core/Socket/Abstractions/IRemoteEndpoint.cs @@ -5,5 +5,5 @@ namespace Tbc.Core.Socket.Abstractions; public interface IRemoteEndpoint { - public Task SendRequest(TRequest request, CancellationToken canceller = default); + public Task SendRequest(TRequest request, CancellationToken canceller = default); } \ No newline at end of file diff --git a/src/components/tbc.core/Socket/SocketServer.cs b/src/components/tbc.core/Socket/SocketServer.cs index 7dc0fb9..83f5dc8 100644 --- a/src/components/tbc.core/Socket/SocketServer.cs +++ b/src/components/tbc.core/Socket/SocketServer.cs @@ -149,7 +149,7 @@ private async Task ReceiveAndHandle(CancellationToken ct = defaul } } - public async Task SendRequest(TRequest request, CancellationToken ct = default) + public async Task SendRequest(TRequest request, CancellationToken ct = default) { if (request == null) throw new ArgumentNullException(nameof(request)); @@ -158,7 +158,7 @@ private async Task ReceiveAndHandle(CancellationToken ct = defaul _log("ignoring attempt to send message on finished socket server, please find the caller " + "who did this and prevent them from doing this >:)"); - return default!; + return default; } var responseMessageId = diff --git a/src/components/tbc.host/Components/FileEnvironment/FileEnvironment.cs b/src/components/tbc.host/Components/FileEnvironment/FileEnvironment.cs index bcacf8b..05a7d9e 100644 --- a/src/components/tbc.host/Components/FileEnvironment/FileEnvironment.cs +++ b/src/components/tbc.host/Components/FileEnvironment/FileEnvironment.cs @@ -93,6 +93,9 @@ private async Task TryLoadLoadContext() var ctx = JsonConvert.DeserializeObject( await File.ReadAllTextAsync($"{_loadContext}.json")); + if (ctx is null) + return; + foreach (var file in ctx.WatchedFiles.Select(x => new ChangedFile { Path = x, Contents = File.ReadAllText(x) })) IncrementalCompiler.StageFile(file, silent: true); @@ -122,6 +125,8 @@ public async Task SetupReferenceTracking() var tempFilePath = FileSystem.Path.GetTempFileName(); var targetHello = await Client.Hello(new HostHello { SharedHostFilePath = tempFilePath }); + if (targetHello is null) + throw new Exception("Remote disconnected"); var sharedFilesystem = targetHello.CanAccessSharedHostFile; var existingReferences = new List(); @@ -344,7 +349,7 @@ private async Task AddSharedFilesystemReference(TargetHello targetHello, List _fileSystem.FileInfo.FromFileName(x).LastWriteTime) + .OrderByDescending(x => _fileSystem.FileInfo.New(x).LastWriteTime) .ToList(); var usings = matches diff --git a/src/components/tbc.host/Components/IncrementalCompiler/IncrementalCompiler.cs b/src/components/tbc.host/Components/IncrementalCompiler/IncrementalCompiler.cs index 0d1eedc..aaeeac3 100644 --- a/src/components/tbc.host/Components/IncrementalCompiler/IncrementalCompiler.cs +++ b/src/components/tbc.host/Components/IncrementalCompiler/IncrementalCompiler.cs @@ -244,13 +244,13 @@ public void WriteEmittedAssembly(EmittedAssembly emittedAssembly) { Logger.LogInformation("Writing emitted assembly {@Assembly}", emittedAssembly); - var peOut = _fileSystem.Path.Combine(_options.WriteAssembliesPath, $"{emittedAssembly.AssemblyName}.dll"); - var pdOut = _fileSystem.Path.Combine(_options.WriteAssembliesPath, $"{emittedAssembly.AssemblyName}.pdb"); + var peOut = _fileSystem.Path.Combine(_options.WriteAssembliesPath!, $"{emittedAssembly.AssemblyName}.dll"); + var pdOut = _fileSystem.Path.Combine(_options.WriteAssembliesPath!, $"{emittedAssembly.AssemblyName}.pdb"); _fileSystem.File.WriteAllBytes(peOut, emittedAssembly.Pe); - if (_options.EmitDebugInformation) - _fileSystem.File.WriteAllBytes(pdOut, emittedAssembly.Pd); + if (_options.EmitDebugInformation && emittedAssembly.Pd is {} pdb) + _fileSystem.File.WriteAllBytes(pdOut, pdb); } public void AddMetadataReference(AssemblyReference asm) diff --git a/src/components/tbc.host/Components/TargetClient/ITargetClient.cs b/src/components/tbc.host/Components/TargetClient/ITargetClient.cs index e73851d..8ebe91b 100644 --- a/src/components/tbc.host/Components/TargetClient/ITargetClient.cs +++ b/src/components/tbc.host/Components/TargetClient/ITargetClient.cs @@ -14,7 +14,7 @@ public interface ITargetClient : IDisposable Task WaitForTerminalState(); IObservable ClientChannelState { get; } - Task Hello(HostHello hello); + Task Hello(HostHello hello); Task> AssemblyReferences(List existing); Task> CommandRequests(); Task RequestClientExecAsync(ExecuteCommandRequest req); diff --git a/src/components/tbc.host/Components/TargetClient/SocketTargetClient.cs b/src/components/tbc.host/Components/TargetClient/SocketTargetClient.cs index b6b8ade..3d7b769 100644 --- a/src/components/tbc.host/Components/TargetClient/SocketTargetClient.cs +++ b/src/components/tbc.host/Components/TargetClient/SocketTargetClient.cs @@ -83,8 +83,8 @@ public async Task WaitForConnection() } } - public Task Hello(HostHello hello) => - Target!.SendRequest(hello); + public Task Hello(HostHello hello) + => Target!.SendRequest(hello); public Task> AssemblyReferences(List assemblyReferences) { @@ -99,15 +99,18 @@ public Task> AssemblyReferences(List> CommandRequests() => Task.FromResult(_incomingCommandRequests.ToAsyncEnumerable()); - public Task RequestClientExecAsync(ExecuteCommandRequest req) - => Target!.SendRequest(req); + public async Task RequestClientExecAsync(ExecuteCommandRequest req) + { + var result = await Target!.SendRequest(req); + return result ?? new Outcome { Success = false, Messages = new() { new() { Message = "Socket disconnected" } } }; + } public async Task RequestClientLoadAssemblyAsync(LoadDynamicAssemblyRequest req) { var sw = Stopwatch.StartNew(); var result = await Target!.SendRequest(req); Logger.LogInformation("Round trip for LoadAssembly with primary type {PrimaryTypeName}, {Duration}ms", req.PrimaryTypeName, sw.ElapsedMilliseconds); - return result; + return result ?? new Outcome { Success = false, Messages = new() { new() { Message = "Socket disconnected" } } }; } public Task WaitForTerminalState() =>