diff --git a/Program.cs b/Program.cs index 88a7f69..5883c8e 100644 --- a/Program.cs +++ b/Program.cs @@ -39,7 +39,7 @@ namespace directors_assistant justArgs.AddRange(ec.args); var commandPath = cmdAndArgs[0]; var commandArguments = String.Join(' ', justArgs); - if (ec.timeout > TimeSpan.Zero) + if (ec.timeout != null && ec.timeout > TimeSpan.Zero) { executeTimed(cmd.name, commandPath, commandArguments, ec.timeout); } @@ -72,7 +72,7 @@ namespace directors_assistant process.Start(); process.BeginErrorReadLine(); process.BeginOutputReadLine(); - if (timeout > TimeSpan.Zero) + if (timeout != null && timeout > TimeSpan.Zero) { Task.WaitAny( Task.Run(() => @@ -145,19 +145,32 @@ namespace directors_assistant }); }); - stopwatch.Start(); - process.Start(); - process.BeginErrorReadLine(); - process.BeginOutputReadLine(); - process.WaitForExit(); - stopwatch.Stop(); - Console.WriteLine($"{commandName} returned {process.ExitCode} after {stopwatch.ElapsedMilliseconds}ms"); - telefranz.ProduceMessage(new silver_messages.directorial.command_completed() + try { - command = commandName, - runtimeMilliseconds = stopwatch.ElapsedMilliseconds, - exit_code = process.ExitCode - }); + stopwatch.Start(); + process.Start(); + process.BeginErrorReadLine(); + process.BeginOutputReadLine(); + process.WaitForExit(); + stopwatch.Stop(); + Console.WriteLine($"{commandName} returned {process.ExitCode} after {stopwatch.ElapsedMilliseconds}ms"); + telefranz.ProduceMessage(new silver_messages.directorial.command_completed() + { + command = commandName, + runtimeMilliseconds = stopwatch.ElapsedMilliseconds, + exit_code = process.ExitCode + }); + } + catch(Exception e) + { + Console.Error.WriteLine($"{commandName} FATAL: {JsonConvert.SerializeObject(e)}"); + telefranz.ProduceMessage(new silver_messages.directorial.command_error() + { + stderr = e.Message, + command = commandName, + runtime = (uint)stopwatch.ElapsedMilliseconds + }); + } } private static Process readableProcess(string commandPath, string commandArguments)