Simplify error message, if no main-is is given in an exitcode-stdio-1.0 test-suite
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
Cabal gives a slightly confusing error message for test-suites if the `type: exitcode-stdio-1.0` is specified but no `main-is`.
```
Errors encountered when parsing cabal file ./test-hls.cabal:
test-hls.cabal:12:1: error:
Test suite "tests" is missing required field "type" or the field is not present in all conditional branches. The available test types are: exitcode-stdio-1.0, detailed-0.9
10 | MyLib
11 |
12 | test-suite tests
| ^
test-hls.cabal:12:1: error:
The 'main-is' field is required for the exitcode-stdio-1.0 test suite type.
10 | MyLib
11 |
12 | test-suite tests
| ^
```
While the second error is accurate, the first error should reference the first or not be displayed at all.
**To Reproduce**
Steps to reproduce the behavior:
```sh
$ mkdir teststuff
$ cabal init -n --lib --no-comments
# modify cabal file:
$ cat teststuff.cabal
cabal-version: 3.0
name: teststuff
version: 0.1.0.0
build-type: Simple
library
exposed-modules: MyLib
build-depends: base ^>=4.17.1.0
hs-source-dirs: src
default-language: Haskell2010
test-suite tests
type: exitcode-stdio-1.0
build-depends: base
$ cabal build
Errors encountered when parsing cabal file ./teststuff.cabal:
teststuff.cabal:12:1: error:
Test suite "tests" is missing required field "type" or the field is not present in all conditional branches. The available test types are: exitcode-stdio-1.0, detailed-0.9
10 | default-language: Haskell2010
11 |
12 | test-suite tests
| ^
teststuff.cabal:12:1: error:
The 'main-is' field is required for the exitcode-stdio-1.0 test suite type.
10 | default-language: Haskell2010
11 |
12 | test-suite tests
| ^
```
**Expected behavior**
The error message should tell you the second message only.
**System information**
- `cabal` cabal-install version 3.10.1.0
**Additional context**
I am running into these error messages more often, since HLS can now give life feedback to cabal files while you write them.
Thus, you see such parse errors much more often.
In the terminal, it works relatively OK since you tend to read the last message first. In HLS, however, you tend to read the first diagnostic:

At least I got mightily confused, since the `type` is specified right next to it.
Contributor guide
Research direction
Reproduce the duplicate diagnostics using the shown teststuff.cabal contents and cabal build. Trace the validation that reports the missing type alongside the separate main-is error. Done means the invalid exitcode-stdio-1.0 suite reports only the accurate main-is diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100