Skip to content

bug: Returning pointers to custom errors causes a non-recovered panic #806

@barak-bem

Description

@barak-bem

Hello! My team recently ran into an issue where returning a nil pointer to a custom error (which we use to attach our own business context) in a Work(...) function caused our whole service to die due to a panic in job_executor.go. We heavily use the custom fields in our error handler.

This can be reproduced like so:

type CustomError {
    InternalErr error
}

type JobWorker struct {
    river.WorkerDefaults[workers.JobWorkerArgs
}

func (jw *JobWorker) Work(ctx context.Context, job *river.Job[workers.JobWorkerArgs]) error {
    var customErr *CustomError
    return customErr
}

Totally aware that this is a classic typed nil issue! However I believe it's unfortunate that this can compile and take down the server with very little observability.

We fixed this by adding a check everywhere that looks like this:

if customErr != nil {
     return customErr
}

return nil

Would it be possible to either:

  1. Support pointers to custom errors (this is preferred by our team)
  2. Recover from the panics within the job executor to avoid bringing down the service

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