Skip to content

Include the context name for errors that happen in the non-default context #10378

@jchavarri

Description

@jchavarri

Consider this example (it uses Melange but that's only for demo purposes, could happen in any multi-context setup):

  $ cat > dune-project << EOF
  > (lang dune 3.13)
  > (using melange 0.1)
  > (package (name bar) (allow_empty))
  > (package (name baz) (allow_empty))
  > EOF

  $ cat > dune-workspace << EOF
  > (lang dune 3.13)
  > 
  > (context default)
  > 
  > (context
  >  (default
  >   (name melange)))
  > EOF
  $ cat > dune << EOF
  > (library
  >  (name foo)
  >  (public_name bar.foo)
  >  (enabled_if (= %{context_name} "default")))
  > (library
  >  (name foo)
  >  (public_name baz.foo)
  >  (modes melange)
  >  (enabled_if (= %{context_name} "melange")))
  > EOF

  $ cat > foo.ml <<EOF
  > let t = Str.regexp
  > EOF

  $ dune build
  File "foo.ml", line 1, characters 8-18:
  1 | let t = Str.regexp
              ^^^^^^^^^^
  Error: Unbound module Str
  [1]

The error message does not allow the user to know under which context the error is happening. This can be quite confusing when using more than one context at scale.

I wonder if Dune could include the context name for "alt contexts" (non-default), similarly to what is done currently for display=short, e.g.:

  $ dune build
  [melange]
  File "foo.ml", line 1, characters 8-18:
  1 | let t = Str.regexp
              ^^^^^^^^^^
  Error: Unbound module Str
  [1]

cc @davesnx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions