Skip to content

Null reference exception inside exception handling, loss of original exception #178

@NealCallaghan

Description

@NealCallaghan

Inside of the App.Start method there is exception handling:

        catch (Exception ex)
        {
            Status = Apps.Status.Stopped;
            await Events.Emit(
                null!,
                EventType.Error,
                new ErrorEvent() { Exception = ex }
            );
        }

The null! is causing a null reference exception and the user of the library is not getting the original call stack.

The exception happens in the OnErrorEvent on the sender.Equals

    protected async Task OnErrorEvent(IPlugin sender, ErrorEvent @event, CancellationToken cancellationToken = default)
    {
        cancellationToken = @event.Context?.CancellationToken ?? cancellationToken;
        Logger.Error(@event.Exception);

        if (@event.Exception is HttpException ex)
        {
            Logger.Error(ex.Request?.RequestUri?.ToString());

            if (ex.Request?.Content is not null)
            {
                var content = await ex.Request.Content.ReadAsStringAsync();
                Logger.Error(content);
            }
        }

        foreach (var plugin in Plugins)
        {
            if (sender.Equals(plugin)) continue;
            await plugin.OnError(this, sender, @event, cancellationToken);
        }
    }

I would be more than happy to look into this and fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions