haskell / haskell/cabal

Cabal repl confusing error message for non-exposed module

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

Description

**Describe the bug**
When working with code, we often wish to open the module we are working with in ghci. The way to do this with cabal is "cabal repl ".

If we forget to include the module in exposed-module we get a quite confusing error message from cabal:

```
$ cabal repl MyModule.hs
Error: [Cabal-7121]
Failed extracting script block: `{- cabal:` start marker not found
```

Notably if we drop the ".hs" extension in the filename, we get a much better error message:

```
$ cabal repl MyModule
Error: [Cabal-7076]
Cannot open a repl for the package MyModule, it is not in this project (either directly or indirectly). If you want to add it to the project then edit the cabal.project file.
```

I feel the good error message should be used in both situations. Why not just omit the .hs in the name? Well, cabal repl is frequently launched from editor keybinds where finding out the current file name is easy, but finding out the canonical module name can be much harder. And the .hs version does work perfectly as long as the module is in exposed-modules.

**To Reproduce**
Steps to reproduce the behavior:

Clone this gist and execute "cabal repl MyModule":
https://gist.github.com/jforberg/bcf4debd9be3f37352827765636dc719

**Expected behavior**
The second error message should be used in both situations.

**System information**
Arch linux, GHC 9.10.2, Cabal 3.12.1.0.

**Additional context**
N/A

Contributor guide

Open the contributing guide

Research direction

Start at the `cabal repl` command path and reproduce the behavior with `cabal repl MyModule.hs` when the module is not exposed. Compare it with `cabal repl MyModule`; done means the filename form reports the same package/module error instead of the script-block extraction error.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.