//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Reflection;
using System.Diagnostics;
using System.Runtime.CompilerServices;

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

static partial class fatal {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[u.doesnt_return][MethodImpl( MethodImplOptions.NoInlining )]
public static u.EFake RaiseError( Assembly sourceAssembly, string causeOrCategory )
{
   var stackTrace = new StackTrace( 1, true );
   return RaiseError(PrepareArgs(() =>
      new u.FatalErrorArgs( sourceAssembly, causeOrCategory ){
         StackTrace = stackTrace
      }));
}

[u.doesnt_return][MethodImpl( MethodImplOptions.NoInlining )]
public static u.EFake RaiseError( Assembly sourceAssembly,
                                  [u.not_negative] int skipFrames,
                                  string causeOrCategory )
{
   var stackTrace = new StackTrace( VerifyStackFrames( skipFrames ) + 1, true );
   return RaiseError(PrepareArgs(() =>
      new u.FatalErrorArgs( sourceAssembly, causeOrCategory ){
         StackTrace = stackTrace
      }));
}

//--------------------------------------------------------------------------------------------------

[u.doesnt_return][MethodImpl( MethodImplOptions.NoInlining )]
public static u.EFake RaiseError( Assembly sourceAssembly,
                                  string causeOrCategory, string errorMessage )
{
   var stackTrace = new StackTrace( 1, true );
   return RaiseError(PrepareArgs(() =>
      new u.FatalErrorArgs( sourceAssembly, causeOrCategory ){
         ErrorMessage = errorMessage,
         StackTrace = stackTrace
      }));
}
[u.doesnt_return][MethodImpl( MethodImplOptions.NoInlining )]
public static u.EFake RaiseError( Assembly sourceAssembly, string causeOrCategory,
                                  string errorMessageFmt, object?[] args )
{
   var stackTrace = new StackTrace( 1, true );
   return RaiseError(PrepareArgs(() =>
      new u.FatalErrorArgs( sourceAssembly, causeOrCategory ){
         ErrorMessage = u.fatal_impl.FMT( errorMessageFmt, args ),
         StackTrace = stackTrace
      }));
}

[u.doesnt_return][MethodImpl( MethodImplOptions.NoInlining )]
public static u.EFake RaiseError( Assembly sourceAssembly, [u.not_negative] int skipFrames,
                                  string causeOrCategory, string errorMessage )
{
   var stackTrace = new StackTrace( VerifyStackFrames( skipFrames ) + 1, true );
   return RaiseError(PrepareArgs(() =>
      new u.FatalErrorArgs( sourceAssembly, causeOrCategory ){
         ErrorMessage = errorMessage,
         StackTrace = stackTrace
      }));
}
[u.doesnt_return][MethodImpl( MethodImplOptions.NoInlining )]
public static u.EFake RaiseError( Assembly sourceAssembly, [u.not_negative] int skipFrames,
                                  string causeOrCategory,
                                  string errorMessageFmt, object?[] args )
{
   var stackTrace = new StackTrace( VerifyStackFrames( skipFrames ) + 1, true );
   return RaiseError(PrepareArgs(() =>
      new u.FatalErrorArgs( sourceAssembly, causeOrCategory ){
         ErrorMessage = u.fatal_impl.FMT( errorMessageFmt, args ),
         StackTrace = stackTrace
      }));
}

//--------------------------------------------------------------------------------------------------

[u.doesnt_return][MethodImpl( MethodImplOptions.NoInlining )]
public static u.EFake RaiseError( Assembly sourceAssembly, string causeOrCategory, Exception e )
{
   var stackTrace = new StackTrace( 1, true );
   return RaiseError(PrepareArgs(() =>
      new u.FatalErrorArgs( sourceAssembly, causeOrCategory ){
         Exception = e,
         StackTrace = stackTrace
      }));
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // fatal

} // user_rtx (.wasm)
