gleam-lang / gleam-lang/stdlib

Consider adding a describe_error function to error types

Open
#914 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Gleam
Stars
710
Forks
225
Avg merge
5h 52m
Merged PRs (30d)
3

Description

Howdy!

There's a particular pattern that's popped up in some Gleam packages, where modules that expose an error type `Error` also expose a `fn describe_error(e: Error) -> String` for stringifying said error. This functionality is especially helpful for logging in application code or using an ad hoc error type like the one provided in the `snag` package.

I wonder if we could implement this pattern in the stdlib. I have a PR showing what this might look like for the `DecodeError` type in the `dynamic/decode` package [here](https://github.com/gleam-lang/stdlib/pull/909). To be clear I have no strong opinions about the *format* of the error at the moment.

Off the top of my head, I don't know if any other module in the standard library exposes a custom error type.

I think a function like this might be useful for libraries using the decode module as well, for example: [gleam/json exposes an error type that wraps the DecodeError](https://hexdocs.pm/gleam_json/gleam/json.html#DecodeError)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.