A package for creating helpful, and pretty CLI messages.
✨ This project is written in pure Gleam so you can use it anywhere Gleam runs: Erlang, Elixir, Node, Deno, and the browser!
error: mismatched types
┌─ example.gleam:2:3
│
│ let a =
2 │ 1 + "hello"
│ ~~~~~~~~~~~
│
expected type `Num` got type `Str`
import gleam/io
import hug
pub fn main() {
let source = "let six = 5 + 1.0"
source
|> hug.error(
in: "example.gleam",
from: #(1, 10),
to: #(1, 17),
message: "invalid type",
hint: "can not add an `Int` to a `Float`"
)
|> io.println_error()
}
If available on Hex this package can be added to your Gleam project:
gleam add hug
and its documentation can be found at https://hexdocs.pm/hug.
The name hug
is inspired by Mark Rendle's talk The Worst Programming Language Ever where he refers error messages in Rust as "a hug from the compiler".