-
Notifications
You must be signed in to change notification settings - Fork 40
Description
Hello! I ran into a problem while writing some custom error reporting for resolution failure for the Gleam compiler. What I do is I start from a DerivationTree
, transform it a bit, and report a pretty printed error message showing the failing constraints along with version ranges. For example the following derivation tree:
// I'm omitting terms and ids and pretty printing the version ranges...
Derived {
cause1: Derived {
cause1: FromDepOf {
wisp: 1.1.0,
gleam_json: 0.6.0 <= v < 2.0.0,
},
cause2: FromDepOf {
prova: 0.0.0,
wisp: 1.1.0,
},
},
cause2: FromDepOf {
prova: 0.0.0,
gleam_json: 2.0.0 <= v < 3.0.0,
},
}
Gets turned into:
Unable to find compatible versions for the version constraints in your
gleam.toml:
- `prova` requires `wisp` to be `1.1.0`
- and all versions of `wisp` in that range require `gleam_json` to be
`0.6.0 <= v < 2.0.0`
- but `prova` also requires `gleam_json` to be `2.0.0 <= v < 3.0.0`
- and there is no version of `gleam_json` that satiesfies both constraints
One thing I'd like to change is the default look of version ranges once they're printed: for example having >= 2.0.0 and < 3.0.0
instead of 2.0.0 <= v < 3.0.0
; this would look more familiar to a Gleam programmer since it more closely resembles how one would write a version constraint in Gleam.
My problem is that the only way I found to turn a Range<_>
into a string is using the default fmt
implementation and since the segments
field is private I cannot roll my own pretty printing implementation for ranges. Could the package expose a way to access a range's segments?
Thank you!