From a256ea640614a1e9ef9a52220daa13a135f05197 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Sun, 10 May 2026 12:14:32 -0500 Subject: [PATCH] Log script errors, avoid silent failures in package scripts --- LANCommander.SDK/PowerShell/PowerShellScript.cs | 12 +++++++++++- LANCommander.Server.Services/GameService.cs | 8 +++++++- .../RedistributableService.cs | 9 ++++++++- LANCommander.Server.Services/ToolService.cs | 9 ++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/LANCommander.SDK/PowerShell/PowerShellScript.cs b/LANCommander.SDK/PowerShell/PowerShellScript.cs index 153af40f..1f38a3c6 100644 --- a/LANCommander.SDK/PowerShell/PowerShellScript.cs +++ b/LANCommander.SDK/PowerShell/PowerShellScript.cs @@ -235,11 +235,21 @@ namespace LANCommander.SDK.PowerShell { await dbg.BreakAsync(DebugContext); }); - + + if (Context.HadErrors) + { + foreach (var error in Context.Streams.Error) + { + Logger.LogError("Script error: {InvocationName} : {ErrorMessage}", error.InvocationInfo?.InvocationName, error.Exception?.Message); + } + } + var returnValue = Context.Runspace.SessionStateProxy.PSVariable.GetValue("Return"); if (returnValue != null) result = (T)returnValue; + else + Logger.LogWarning("Script did not set $Return variable"); } catch (Exception ex) { diff --git a/LANCommander.Server.Services/GameService.cs b/LANCommander.Server.Services/GameService.cs index 84e9a606..e8e0a022 100644 --- a/LANCommander.Server.Services/GameService.cs +++ b/LANCommander.Server.Services/GameService.cs @@ -225,7 +225,13 @@ namespace LANCommander.Server.Services { var package = await scriptClient.Game_RunPackageScriptAsync(mapper.Map(script), mapper.Map(game)); - if (!Directory.Exists(package.Path)) + if (package == null) + { + logger?.LogError("Could not package game {GameTitle}, the package script did not return a result", game.Title); + continue; + } + + if (String.IsNullOrWhiteSpace(package.Path) || !Directory.Exists(package.Path)) { logger?.LogError("Could not package game {GameTitle}, the path {Path} could not be found", game.Title, package.Path); continue; diff --git a/LANCommander.Server.Services/RedistributableService.cs b/LANCommander.Server.Services/RedistributableService.cs index f5e64bf1..22c27fdd 100644 --- a/LANCommander.Server.Services/RedistributableService.cs +++ b/LANCommander.Server.Services/RedistributableService.cs @@ -89,11 +89,18 @@ namespace LANCommander.Server.Services { var package = await scriptClient.Redistributable_RunPackageScriptAsync(mapper.Map(script), mapper.Map(redistributable)); - if (!Directory.Exists(package.Path)) + if (package == null) + { + logger?.LogError("Could not package redistributable {RedistributableName}, the package script did not return a result", redistributable.Name); + continue; + } + + if (String.IsNullOrWhiteSpace(package.Path) || !Directory.Exists(package.Path)) { logger?.LogError( "Could not package redistributable {RedistributableName}, the path {Path} could not be found", redistributable.Name, package.Path); + continue; } var archive = new Archive diff --git a/LANCommander.Server.Services/ToolService.cs b/LANCommander.Server.Services/ToolService.cs index c715c7f6..b81c9712 100644 --- a/LANCommander.Server.Services/ToolService.cs +++ b/LANCommander.Server.Services/ToolService.cs @@ -89,11 +89,18 @@ namespace LANCommander.Server.Services { var package = await scriptClient.Tool_RunPackageScriptAsync(mapper.Map(script), mapper.Map(tool)); - if (!Directory.Exists(package.Path)) + if (package == null) + { + logger?.LogError("Could not package tool {ToolName}, the package script did not return a result", tool.Name); + continue; + } + + if (String.IsNullOrWhiteSpace(package.Path) || !Directory.Exists(package.Path)) { logger?.LogError( "Could not package tool {ToolName}, the path {Path} could not be found", tool.Name, package.Path); + continue; } var archive = new Archive