public static bool TryGetExceptionFromCliArgs(string[] args, [NotNullWhen(true)] out SerializableException?exception)
    {
        exception = null;
        try
        {
            var commandArgument   = args.SingleOrDefault(x => x == "crashreport");
            var parameterArgument = args.SingleOrDefault(x => x.Contains("-exception="));

            if (commandArgument is not null && parameterArgument is not null)
            {
                var exceptionString = parameterArgument.Split("=", count: 2)[1].Trim('"');

                exception = SerializableException.FromBase64String(exceptionString);
                return(true);
            }
        }
        catch (Exception ex)
        {
            // Report the current exception.
            exception = ex.ToSerializableException();

            Logger.LogCritical($"There was a problem: '{ex}'.");
            return(true);
        }

        return(false);
    }
Beispiel #2
0
 public void SetShowCrashReport(string base64ExceptionString, int attempts)
 {
     Attempts = attempts;
     Base64ExceptionString = base64ExceptionString;
     SerializedException   = SerializableException.FromBase64String(Base64ExceptionString);
     IsReport = true;
 }
        public static bool TryGetExceptionFromCliArgs(string[] args, [NotNullWhen(true)] out SerializableException?exception)
        {
            exception = null;
            try
            {
                if (args.Length < 2)
                {
                    return(false);
                }

                if (args[0].Contains("crashreport") && args[1].Contains("-exception="))
                {
                    var exceptionString = args[1].Split("=", count: 2)[1].Trim('"');

                    exception = SerializableException.FromBase64String(exceptionString);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                // Report the current exception.
                exception = ex.ToSerializableException();

                Logger.LogCritical($"There was a problem: '{ex}'.");
                return(true);
            }

            return(false);
        }
    public void SerializableExceptionTest()
    {
        var message         = "Foo Bar Buzz";
        var innerMessage    = "Inner Foo Bar Buzz";
        var innerStackTrace = "";

        Exception ex;
        string?   stackTrace;

        try
        {
            try
            {
                throw new OperationCanceledException(innerMessage);
            }
            catch (Exception inner)
            {
                innerStackTrace = inner.StackTrace;
                throw new InvalidOperationException(message, inner);
            }
        }
        catch (Exception x)
        {
            stackTrace = x.StackTrace;
            ex         = x;
        }

        var serializableException = ex.ToSerializableException();
        var base64string          = SerializableException.ToBase64String(serializableException);
        var result = SerializableException.FromBase64String(base64string);

        Assert.Equal(message, result.Message);
        Assert.Equal(stackTrace, result.StackTrace);
        Assert.Equal(typeof(InvalidOperationException).FullName, result.ExceptionType);

        Assert.Equal(innerMessage, result.InnerException?.Message);
        Assert.Equal(innerStackTrace, result.InnerException?.StackTrace);
        Assert.Equal(typeof(OperationCanceledException).FullName, result.InnerException?.ExceptionType);

        var serializableException2 = ex.ToSerializableException();

        Assert.Equal(serializableException, serializableException2);
    }