|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.Globalization; |
3 | 4 | using System.IO; |
4 | 5 | using System.Linq; |
5 | 6 | using Common.Logging; |
@@ -61,17 +62,29 @@ public override ScriptResult Execute(string script, params string[] scriptArgs) |
61 | 62 | var argsToPass = new List<object>(); |
62 | 63 | foreach (var argument in tokens.Skip(1)) |
63 | 64 | { |
64 | | - try |
| 65 | + var argumentResult = ScriptEngine.Execute( |
| 66 | + argument, _scriptArgs, References, DefaultNamespaces, ScriptPackSession); |
| 67 | + |
| 68 | + if (argumentResult.CompileExceptionInfo != null) |
65 | 69 | { |
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 | + } |
68 | 74 |
|
69 | | - argsToPass.Add(argumentResult.ReturnValue ?? argument); |
| 75 | + if (argumentResult.ExecuteExceptionInfo != null) |
| 76 | + { |
| 77 | + throw new Exception( |
| 78 | + GetInvalidCommandArgumentMessage(argument), |
| 79 | + argumentResult.ExecuteExceptionInfo.SourceException); |
70 | 80 | } |
71 | | - catch (Exception) |
| 81 | + |
| 82 | + if (!argumentResult.IsCompleteSubmission) |
72 | 83 | { |
73 | | - argsToPass.Add(argument); |
| 84 | + throw new Exception(GetInvalidCommandArgumentMessage(argument)); |
74 | 85 | } |
| 86 | + |
| 87 | + argsToPass.Add(argumentResult.ReturnValue); |
75 | 88 | } |
76 | 89 |
|
77 | 90 | var commandResult = command.Execute(this, argsToPass.ToArray()); |
@@ -157,5 +170,10 @@ public override ScriptResult Execute(string script, params string[] scriptArgs) |
157 | 170 | Console.ResetColor(); |
158 | 171 | } |
159 | 172 | } |
| 173 | + |
| 174 | + private static string GetInvalidCommandArgumentMessage(string argument) |
| 175 | + { |
| 176 | + return string.Format(CultureInfo.InvariantCulture, "Argument is not a valid expression: {0}", argument); |
| 177 | + } |
160 | 178 | } |
161 | 179 | } |
0 commit comments