haskell / haskell/cabal

`--constrain` should print an ad hoc message for invalid constraints

Open
#9,362 0 comments 0 reactions 0 assignees View on GitHub
type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the feature request**

I'd like Cabal to distinguish between two situations:

1. a constraint passed to `--constrain` mentions a version that doesn't exist;
2. a constraint passed to `--constrain` can't be satisfied because it conflicts with constraints set by other packages.

**Additional context**

Here's me trying to build a project with a dependency whose version is not supported by the project:

```
$ grep '\' hakyll.cabal
text >= 0.11 && < 1.3 || >= 2.0 && < 2.1,
text >= 0.11 && < 1.3 || >= 2.0 && < 2.1,
$ cabal build --constrain 'text == 2.1'
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: hakyll-4.16.2.0 (user goal)
[__1] next goal: text (dependency of hakyll)
[__1] rejecting: text-2.0.2/installed-2.0.2 (constraint from command line flag
requires ==2.1)
[__1] rejecting: text-2.1 (conflict: hakyll => text>=0.11 && <1.3 || >=2.0 &&
<2.1)
[__1] rejecting: text-2.0.2, text-2.0.1, text-2.0, text-1.2.5.0, text-1.2.4.1,
text-1.2.4.0, text-1.2.3.2, text-1.2.3.1, text-1.2.3.0, text-1.2.2.2,
text-1.2.2.1, text-1.2.2.0, text-1.2.1.3, text-1.2.1.2, text-1.2.1.1,
text-1.2.1.0, text-1.2.0.6, text-1.2.0.5, text-1.2.0.4, text-1.2.0.3,
text-1.2.0.2, text-1.2.0.0, text-1.1.1.4, text-1.1.1.3, text-1.1.1.2,
text-1.1.1.1, text-1.1.1.0, text-1.1.0.1, text-1.1.0.0, text-1.0.0.1,
text-1.0.0.0, text-0.11.3.1, text-0.11.3.0, text-0.11.2.3, text-0.11.2.2,
text-0.11.2.1, text-0.11.2.0, text-0.11.1.13, text-0.11.1.12, text-0.11.1.11,
text-0.11.1.10, text-0.11.1.9, text-0.11.1.8, text-0.11.1.7, text-0.11.1.6,
text-0.11.1.5, text-0.11.1.3, text-0.11.1.2, text-0.11.1.1, text-0.11.1.0,
text-0.11.0.8, text-0.11.0.7, text-0.11.0.6, text-0.11.0.5, text-0.11.0.4,
text-0.11.0.3, text-0.11.0.2, text-0.11.0.1, text-0.11.0.0, text-0.10.0.2,
text-0.10.0.1, text-0.10.0.0, text-0.9.1.0, text-0.9.0.1, text-0.9.0.0,
text-0.8.1.0, text-0.8.0.0, text-0.7.2.1, text-0.7.1.0, text-0.7.0.1,
text-0.7, text-0.6, text-0.5, text-0.4, text-0.3, text-0.2, text-0.1
(constraint from command line flag requires ==2.1)
[__1] fail (backjumping, conflict set: hakyll, text)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: hakyll, text
```

And here's me trying to build the same project using a version that doesn't exist:

```
$ cabal build --constrain 'text == 100500'
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: hakyll-4.16.2.0 (user goal)
[__1] next goal: text (dependency of hakyll)
[__1] rejecting: text-2.0.2/installed-2.0.2, text-2.1, text-2.0.2, text-2.0.1,
text-2.0, text-1.2.5.0, text-1.2.4.1, text-1.2.4.0, text-1.2.3.2,
text-1.2.3.1, text-1.2.3.0, text-1.2.2.2, text-1.2.2.1, text-1.2.2.0,
text-1.2.1.3, text-1.2.1.2, text-1.2.1.1, text-1.2.1.0, text-1.2.0.6,
text-1.2.0.5, text-1.2.0.4, text-1.2.0.3, text-1.2.0.2, text-1.2.0.0,
text-1.1.1.4, text-1.1.1.3, text-1.1.1.2, text-1.1.1.1, text-1.1.1.0,
text-1.1.0.1, text-1.1.0.0, text-1.0.0.1, text-1.0.0.0, text-0.11.3.1,
text-0.11.3.0, text-0.11.2.3, text-0.11.2.2, text-0.11.2.1, text-0.11.2.0,
text-0.11.1.13, text-0.11.1.12, text-0.11.1.11, text-0.11.1.10, text-0.11.1.9,
text-0.11.1.8, text-0.11.1.7, text-0.11.1.6, text-0.11.1.5, text-0.11.1.3,
text-0.11.1.2, text-0.11.1.1, text-0.11.1.0, text-0.11.0.8, text-0.11.0.7,
text-0.11.0.6, text-0.11.0.5, text-0.11.0.4, text-0.11.0.3, text-0.11.0.2,
text-0.11.0.1, text-0.11.0.0, text-0.10.0.2, text-0.10.0.1, text-0.10.0.0,
text-0.9.1.0, text-0.9.0.1, text-0.9.0.0, text-0.8.1.0, text-0.8.0.0,
text-0.7.2.1, text-0.7.1.0, text-0.7.0.1, text-0.7, text-0.6, text-0.5,
text-0.4, text-0.3, text-0.2, text-0.1 (constraint from command line flag
requires ==100500)
[__1] fail (backjumping, conflict set: hakyll, text)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: text, hakyll
```

The messages look quite similar, which might lead to all kinds of time-wasters. For example, I got so confused [I thought `--constrain` doesn't work](https://functional.cafe/@minoru/111199587213402915) :sweat_smile:

I wish the second message simply said "text 100500 doesn't exist, are you sure you didn't make a typo?".

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.