Log script errors, avoid silent failures in package scripts

This commit is contained in:
Pat Hartl 2026-05-10 12:14:32 -05:00
parent b3813d7c3c
commit a256ea6406
4 changed files with 34 additions and 4 deletions

View file

@ -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)
{