Skip to content

Commit

Permalink
OnExecute: log inner exceptions (#1751)
Browse files Browse the repository at this point in the history
* OnExecute: log inner exceptions

Log the whole exception chain when an exception gets caught by a program.

* typo fix

* ActionInvoker: use chained exceptions

* CodeGenCommand.Execute: log inner exceptions
  • Loading branch information
yecril71pl committed Dec 24, 2021
1 parent b54ebbb commit 7482cf1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Scaffolding/VS.Web.CG.Core/ActionInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal void BuildCommandLine(CommandLineApplication command)
}
catch (Exception ex)
{
throw new InvalidOperationException(string.Format(MessageStrings.ModelCreationFailed, ex.Message));
throw new InvalidOperationException(string.Format(MessageStrings.ModelCreationFailed, ex.Message), ex);
}
foreach (var param in ActionDescriptor.Parameters)
Expand Down
16 changes: 10 additions & 6 deletions src/Scaffolding/VS.Web.CG.Design/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,18 @@ private static void Execute(string[] args, ConsoleLogger logger)
}
catch(Exception ex)
{
logger.LogMessage(Resources.GenericErrorMessage, LogMessageLevel.Error);
logger.LogMessage(ex.Message, LogMessageLevel.Error);
logger.LogMessage(ex.StackTrace, LogMessageLevel.Trace);
if (!logger.IsTracing)
do
{
logger.LogMessage(Resources.EnableTracingMessage);
logger.LogMessage(Resources.GenericErrorMessage, LogMessageLevel.Error);
logger.LogMessage(ex.Message, LogMessageLevel.Error);
logger.LogMessage(ex.StackTrace, LogMessageLevel.Trace);
if (!logger.IsTracing)
{
logger.LogMessage(Resources.EnableTracingMessage);
}
ex = ex .InnerException;
}
while (!(ex is null));
}
return exitCode;
Expand Down
11 changes: 8 additions & 3 deletions src/Scaffolding/VS.Web.CG/CodeGenCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ public int Execute(string [] args)
}
catch (Exception ex)
{
while (ex is TargetInvocationException)
do
{
while (ex is TargetInvocationException)
{
ex = ex.InnerException;
}
_logger.LogMessage(ex.Message, LogMessageLevel.Error);
_logger.LogMessage(ex.StackTrace);
ex = ex.InnerException;
}
_logger.LogMessage(ex.Message, LogMessageLevel.Error);
_logger.LogMessage(ex.StackTrace);
while (ex is Exception);
}
return 0;
}
Expand Down

0 comments on commit 7482cf1

Please sign in to comment.