diff --git a/src/client/spark/core/Diagnostics/ShellDiagnosticsServiceServer.cs b/src/client/spark/core/Diagnostics/ShellDiagnosticsServiceServer.cs index f9e69f73d..17f1677bd 100644 --- a/src/client/spark/core/Diagnostics/ShellDiagnosticsServiceServer.cs +++ b/src/client/spark/core/Diagnostics/ShellDiagnosticsServiceServer.cs @@ -10,6 +10,7 @@ using Microsoft.Scripting; using Microsoft.Scripting.Hosting; namespace bts.api.diagnostic { + class ShellDiagnosticsServiceServer : ShellDiagnosticServiceBase { readonly ServiceContext _context; readonly List _hosts = new List(); @@ -34,17 +35,6 @@ namespace bts.api.diagnostic { } } - class ErrorLogger : ErrorListener { - private ShellScriptServer _parent; - - public ErrorLogger(ShellScriptServer server) { - _parent = server; - } - public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity) { - _parent.log($"{severity}: {message}"); - } - } - class ShellScriptServer : ShellScriptHostBase { readonly ShellDiagnosticsServiceServer _owner; readonly ScriptEngine _engine = IronPython.Hosting.Python.CreateEngine(); @@ -58,7 +48,7 @@ namespace bts.api.diagnostic { _out = make_output_publisher(); _scope = _engine.CreateScope(); _scope.SetVariable("id", qualifier); - _scope.SetVariable("log", new Action(log)); + _scope.SetVariable("log", new Action(log)); //_scope.SetVariable("help", (object o) => log(o.ToString()) } @@ -68,8 +58,8 @@ namespace bts.api.diagnostic { return Task.FromResult(new VoidMessage()); } - internal void log(string msg) { - log(msg, false); + internal void log(object msg) { + log(msg?.ToString(), false); } internal void log(string msg, bool isEnd) { Console.WriteLine(msg); @@ -82,11 +72,11 @@ namespace bts.api.diagnostic { Task run_code(ScriptSource code) { try { - var result = code.Execute(_scope); - return Task.FromResult(new ScriptResultMessage { Res = ScriptResult.Complete, Message = result ?? "" }); + object result = code.Execute(_scope); + return Task.FromResult(new ScriptResultMessage { Res = ScriptResult.Complete, Message = (result?.ToString()) ?? "" }); } catch (Exception e) { - log($"Exception: {e.Message}"); + //log($"Exception: {e.Message}"); return Task.FromResult(new ScriptResultMessage { Res = ScriptResult.RunError, Message = e.Message }); } } @@ -98,7 +88,7 @@ namespace bts.api.diagnostic { _pending.AppendLine(line); } // CreateScriptSource from pending - var code = _engine.CreateScriptSourceFromString(_pending.ToString(), SourceCodeKind.InteractiveCode); + var code = _engine.CreateScriptSourceFromString(_pending.ToString().TrimStart(' ', '\n', '\r'), SourceCodeKind.InteractiveCode); var parse_result = code.GetCodeProperties(); if (parse_result == ScriptCodeParseResult.IncompleteStatement && code.GetCode().EndsWith(Environment.NewLine+Environment.NewLine)) { parse_result = Microsoft.Scripting.ScriptCodeParseResult.Complete; diff --git a/src/client/sparkcmd/ScriptClient.cs b/src/client/sparkcmd/ScriptClient.cs index ce18a92d8..c9eb30693 100644 --- a/src/client/sparkcmd/ScriptClient.cs +++ b/src/client/sparkcmd/ScriptClient.cs @@ -28,7 +28,10 @@ namespace sparkcmd { Console.WriteLine($"Syntax error: '{result.Message}'"); } else if (status == ScriptResult.RunError) { - Console.WriteLine($"Error executing script: {result.Message}"); + Console.WriteLine($"Exception: {result.Message}"); + } + else if (status == ScriptResult.Complete && !string.IsNullOrEmpty(result.Message)) { + Console.WriteLine(result.Message); } } else { @@ -42,8 +45,11 @@ namespace sparkcmd { Console.WriteLine($"Done. {e.Message}"); } finally { - script.dispose(null); - script.Dispose(); + try { + script.dispose(null); + script.Dispose(); + } + catch (Exception) { } } } }