Skip to content

Commit 3fad43c

Browse files
committed
green: implemented ShouldSurfaceArgumentCompilationErrors, ShouldSurfaceArgumentExecutionErrors, ShouldSurfaceIncompleteArguments
scriptcs#224 scriptcs#237 scriptcs#583
1 parent a795b51 commit 3fad43c

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/ScriptCs.Core/Repl.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.IO;
45
using System.Linq;
56
using Common.Logging;
@@ -61,17 +62,29 @@ public override ScriptResult Execute(string script, params string[] scriptArgs)
6162
var argsToPass = new List<object>();
6263
foreach (var argument in tokens.Skip(1))
6364
{
64-
try
65+
var argumentResult = ScriptEngine.Execute(
66+
argument, _scriptArgs, References, DefaultNamespaces, ScriptPackSession);
67+
68+
if (argumentResult.CompileExceptionInfo != null)
6569
{
66-
var argumentResult = ScriptEngine.Execute(argument, _scriptArgs, References, DefaultNamespaces, ScriptPackSession);
67-
//if Roslyn can evaluate the argument, use its value, otherwise assume the string
70+
throw new Exception(
71+
GetInvalidCommandArgumentMessage(argument),
72+
argumentResult.CompileExceptionInfo.SourceException);
73+
}
6874

69-
argsToPass.Add(argumentResult.ReturnValue ?? argument);
75+
if (argumentResult.ExecuteExceptionInfo != null)
76+
{
77+
throw new Exception(
78+
GetInvalidCommandArgumentMessage(argument),
79+
argumentResult.ExecuteExceptionInfo.SourceException);
7080
}
71-
catch (Exception)
81+
82+
if (!argumentResult.IsCompleteSubmission)
7283
{
73-
argsToPass.Add(argument);
84+
throw new Exception(GetInvalidCommandArgumentMessage(argument));
7485
}
86+
87+
argsToPass.Add(argumentResult.ReturnValue);
7588
}
7689

7790
var commandResult = command.Execute(this, argsToPass.ToArray());
@@ -157,5 +170,10 @@ public override ScriptResult Execute(string script, params string[] scriptArgs)
157170
Console.ResetColor();
158171
}
159172
}
173+
174+
private static string GetInvalidCommandArgumentMessage(string argument)
175+
{
176+
return string.Format(CultureInfo.InvariantCulture, "Argument is not a valid expression: {0}", argument);
177+
}
160178
}
161179
}

0 commit comments

Comments
 (0)