Skip to content

Error message displays debug formatting #348

@musjj

Description

@musjj

I have an error like this:

#[derive(Debug, Clone, Error, Serialize, Type)]
enum ApiError {
    #[error("foo error")]
    Foo,
}

impl rspc::Error for ApiError {
    fn into_procedure_error(self) -> ProcedureError {
        ResolverError::new(self.to_string(), Some(self)).into()
    }
}

But returning this error displays the debug formatting instead of the message foo error:

"data": {
  "code": 500,
  "message": "Resolver(ResolverError(Some(Foo)))",
  "data": null
}

Which is not very user-friendly. Is there a way to have better control of the error message?

It's worst when there's no source:

"data": {
  "code": 500,
  "message": "Resolver(ResolverError(None))",
  "data": null
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions