Permalink
Browse files

shell.me prints errors with stack traces in red to the console

  • Loading branch information...
1 parent 834f67c commit e20e1ce43799ad2cb24e19acb464458797cc00eb @cburgdorf cburgdorf committed Jun 4, 2012
@@ -135,8 +135,9 @@ public void PrintsExceptionsToTheConsole()
commandLoop.Start(new[] { "RaiseException", "--nonInteractive" });
Assert.AreEqual("Unexpected error happended while proceeding the command: RaiseException", console.OutputQueue[0]);
- Assert.AreEqual("Foo", console.OutputQueue[1]);
- Assert.AreEqual("Bar", console.OutputQueue[2]);
+ Assert.AreEqual("Exception: Foo", console.OutputQueue[1]);
+ Assert.IsTrue(console.OutputQueue[2].StartsWith("Stacktrace:"));
+ Assert.AreEqual("Exception: Bar", console.OutputQueue[3]);
}
}
}
@@ -84,12 +84,14 @@ private bool TryToProceedCommand(ICommand command, IEnumerable<string> args)
}
catch (Exception exception)
{
+ Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Unexpected error happended while proceeding the command: " + command.Name);
var exceptionWalker = new ExceptionWalker(exception);
foreach (var message in exceptionWalker.GetExceptionMessages())
{
Console.WriteLine(message);
}
+ Console.ResetColor();
return false;
}
}
@@ -16,7 +16,9 @@ public IEnumerable<string> GetExceptionMessages()
{
while (_exception != null)
{
- yield return _exception.Message;
+ yield return string.Format("Exception: {0}", _exception.Message);
+ if (!string.IsNullOrEmpty(_exception.StackTrace))
+ yield return string.Format("Stacktrace: {0}", _exception.StackTrace);
_exception = _exception.InnerException;
}
}
@@ -1,8 +1,12 @@
-namespace ShellMe.CommandLine
+using System;
+
+namespace ShellMe.CommandLine
{
public interface IConsole
{
void WriteLine(string line);
string ReadLine();
+ ConsoleColor ForegroundColor { get; set; }
+ void ResetColor();
}
}
@@ -1,15 +1,31 @@
-namespace ShellMe.CommandLine
-{
- public class NativeConsoleWrapper : IConsole
+using System;
+
+
+namespace ShellMe.CommandLine
+{public class NativeConsoleWrapper : IConsole
{
public void WriteLine(string line)
{
- System.Console.WriteLine(line);
+ Console.WriteLine(line);
}
public string ReadLine()
{
- return System.Console.ReadLine();
+ return Console.ReadLine();
+ }
+
+ public ConsoleColor ForegroundColor
+ {
+ get { return Console.ForegroundColor; }
+ set
+ {
+ Console.ForegroundColor = value;
+ }
+ }
+
+ public void ResetColor()
+ {
+ Console.ResetColor();
}
}
}
@@ -29,5 +29,11 @@ public string ReadLine()
_commandQueue.RemoveAt(0);
return first;
}
+
+ public ConsoleColor ForegroundColor { get; set; }
+
+ public void ResetColor()
+ {
+ }
}
}

0 comments on commit e20e1ce

Please sign in to comment.