// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
namespace UnrealBuildBase
{
///
/// Implementation of that will return a unique exit code.
///
public class CompilationResultException : BuildLogEventException
{
///
/// The exit code associated with this exception
///
public CompilationResult Result { get; }
readonly bool HasMessage = true;
///
/// Constructor
///
/// The resulting exit code
public CompilationResultException(CompilationResult Result)
: base(LogEvent.Create(LogLevel.Error, "{CompilationResult}", Result))
{
HasMessage = false;
this.Result = Result;
}
///
/// Constructor
///
/// The resulting exit code
/// Event to construct from
public CompilationResultException(CompilationResult Result, LogEvent Event)
: base(Event)
{
this.Result = Result;
}
///
/// Constructor which wraps another exception
///
/// The resulting exit code
/// The inner exception
/// Event to construct from
public CompilationResultException(CompilationResult Result, Exception? InnerException, LogEvent Event)
: base(InnerException, Event)
{
this.Result = Result;
}
///
/// Constructor
///
/// The resulting exit code
/// Event id for the error
/// Formatting string for the error message
/// Arguments for the formatting string
public CompilationResultException(CompilationResult Result, EventId EventId, string Format, params object[] Arguments)
: base(LogEvent.Create(LogLevel.Error, EventId, Format, Arguments))
{
this.Result = Result;
}
///
/// Constructor
///
/// The resulting exit code
/// Formatting string for the error message
/// Arguments for the formatting string
public CompilationResultException(CompilationResult Result, string Format, params object[] Arguments)
: base(LogEvent.Create(LogLevel.Error, Format, Arguments))
{
this.Result = Result;
}
///
/// Constructor which wraps another exception
///
/// The resulting exit code
/// The inner exception being wrapped
/// Format for the message string
/// Format arguments
public CompilationResultException(CompilationResult Result, Exception? InnerException, string Format, params object[] Arguments)
: base(InnerException, LogEvent.Create(LogLevel.Error, default, InnerException, Format, Arguments))
{
this.Result = Result;
}
///
/// Constructor which wraps another exception
///
/// The resulting exit code
/// Event id for the error
/// Inner exception to wrap
/// Structured logging format string
/// Argument objects
public CompilationResultException(CompilationResult Result, Exception? InnerException, EventId EventId, string Format, params object[] Arguments)
: base(InnerException, LogEvent.Create(LogLevel.Error, EventId, InnerException, Format, Arguments))
{
this.Result = Result;
}
///
public override void LogException(ILogger Logger)
{
if (HasMessage)
{
Logger.Log(Event.Level, Event.Id, Event, this, (s, e) => s.ToString());
}
Logger.LogDebug(Event.Id, this, "{Ex}", ExceptionUtils.FormatExceptionDetails(this));
}
}
}