// Copyright Epic Games, Inc. All Rights Reserved. using EpicGames.Core; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Text; namespace UnrealBuildTool { /// /// Base class for exceptions thrown by UBT /// public class BuildException : Exception { /// /// Constructor /// /// The error message to display. public BuildException(string Message) : base(Message) { } /// /// Constructor /// /// An inner exception to wrap /// The error message to display. public BuildException(Exception? InnerException, string Message) : base(Message, InnerException) { } /// /// Constructor /// /// Formatting string for the error message /// Arguments for the formatting string public BuildException(string Format, params object?[] Arguments) : base(String.Format(Format, Arguments)) { } /// /// Constructor which wraps another exception /// /// The inner exception being wrapped /// Format for the message string /// Format arguments public BuildException(Exception InnerException, string Format, params object?[] Arguments) : base(String.Format(Format, Arguments), InnerException) { } /// /// Returns the string representing the exception. Our build exceptions do not show the callstack since they are used to report known error conditions. /// /// Message for the exception public override string ToString() { return Message; } } /// /// Implementation of that captures a full structured logging event. /// class BuildLogEventException : BuildException { /// /// The event object /// public LogEvent Event { get; } /// /// Constructor /// /// Event to construct from public BuildLogEventException(LogEvent Event) : this(null, Event) { } /// /// Constructor /// /// The inner exception /// Event to construct from public BuildLogEventException(Exception? InnerException, LogEvent Event) : base(InnerException, Event.ToString()) { this.Event = Event; } /// /// Constructor /// /// Structured logging format string /// Argument objects public BuildLogEventException(string Format, params object[] Args) : this(LogEvent.Create(LogLevel.Error, Format, Args)) { } /// /// Constructor /// /// Inner exception to wrap /// Structured logging format string /// Argument objects public BuildLogEventException(Exception? InnerException, string Format, params object[] Args) : this(InnerException, LogEvent.Create(LogLevel.Error, default, InnerException, Format, Args)) { } /// /// Constructor /// /// Event id for the error /// Inner exception to wrap /// Structured logging format string /// Argument objects public BuildLogEventException(Exception? InnerException, EventId EventId, string Format, params object[] Args) : this(InnerException, LogEvent.Create(LogLevel.Error, EventId, InnerException, Format, Args)) { } } }