Skip to content

Commit

Permalink
(cake-buildGH-2861) Restore pre 1.0 error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Oct 25, 2020
1 parent 6153bab commit 3a85b8c
Showing 1 changed file with 56 additions and 24 deletions.
80 changes: 56 additions & 24 deletions src/Cake/Commands/DefaultCommand.cs
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Features.Bootstrapping;
using Cake.Features.Building;
Expand Down Expand Up @@ -34,40 +36,70 @@ public sealed class DefaultCommand : Command<DefaultCommandSettings>

public override int Execute(CommandContext context, DefaultCommandSettings settings)
{
// Set log verbosity.
_log.Verbosity = settings.Verbosity;

if (settings.ShowVersion)
try
{
return _version.Run();
// Set log verbosity.
_log.Verbosity = settings.Verbosity;

if (settings.ShowVersion)
{
return _version.Run();
}
else if (settings.ShowInfo)
{
return _info.Run();
}

// Get the build host type.
var host = GetBuildHostKind(settings);

// Run the bootstrapper?
if (!settings.SkipBootstrap || settings.Bootstrap)
{
int bootstrapperResult = PerformBootstrapping(context, settings, host);
if (bootstrapperResult != 0 || settings.Bootstrap)
{
return bootstrapperResult;
}
}

// Run the build feature.
return _builder.Run(context.Remaining, new BuildFeatureSettings(host)
{
Script = settings.Script,
Verbosity = settings.Verbosity,
Exclusive = settings.Exclusive,
Debug = settings.Debug,
NoBootstrapping = settings.SkipBootstrap,
});
}
else if (settings.ShowInfo)
catch (Exception ex)
{
return _info.Run();
return LogException(_log, ex);
}
}

// Get the build host type.
var host = GetBuildHostKind(settings);
private static int LogException<T>(ICakeLog log, T ex) where T : Exception
{
log = log ?? new CakeBuildLog(
new CakeConsole(new CakeEnvironment(new CakePlatform(), new CakeRuntime())));

// Run the bootstrapper?
if (!settings.SkipBootstrap || settings.Bootstrap)
if (log.Verbosity == Verbosity.Diagnostic)
{
log.Error("Error: {0}", ex);
}
else
{
int bootstrapperResult = PerformBootstrapping(context, settings, host);
if (bootstrapperResult != 0 || settings.Bootstrap)
log.Error("Error: {0}", ex.Message);
if (ex is AggregateException aex)
{
return bootstrapperResult;
foreach (var exception in aex.Flatten().InnerExceptions)
{
log.Error("\t{0}", exception.Message);
}
}
}

// Run the build feature.
return _builder.Run(context.Remaining, new BuildFeatureSettings(host)
{
Script = settings.Script,
Verbosity = settings.Verbosity,
Exclusive = settings.Exclusive,
Debug = settings.Debug,
NoBootstrapping = settings.SkipBootstrap,
});
return 1;
}

private BuildHostKind GetBuildHostKind(DefaultCommandSettings settings)
Expand Down

0 comments on commit 3a85b8c

Please sign in to comment.