Skip to content

Warn about unknown keys in hie.yaml instead of failing - #534

Merged
fendor merged 2 commits into
haskell:masterfrom
swinilohani616-dot:unknown-keys-warnings
Nov 24, 2026
Merged

fendor merged 2 commits into
haskell:masterfrom
swinilohani616-dot:unknown-keys-warnings

Conversation

@swinilohani616-dot

@swinilohani616-dot swinilohani616-dot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #344.

At the moment, if hie.yaml has a key hie-bios doesn't recognise in the cabal, stack or bios section,
parsing just fails. That makes it really hard to ever add a new optional key: as soon as someone puts it in their
hie.yaml, anyone on an older HLS can't open the project at all.

As fendor pointed out in the issue, aeson can't turn unknown fields into warnings while it's parsing. So I split
it into two steps. The parsers now quietly skip keys they don't know, and a separate pass over the YAML, using
lists of the keys each section accepts, picks them up as ConfigWarnings. Each warning has a JSONPath saying
where the key was, like $.cradle.bios or, for a nested multi cradle,
$.cradle.multi[0].config.cradle.cabal.components[0].

For the API, I added readConfigWithWarnings, which hands back the warnings along with the config, and exported
ConfigWarning from HIE.Bios.Config. readConfig has the same type as before; it just ignores unknown keys now
instead of failing. When a cradle gets loaded, each warning is logged at Warning level through a new
LogConfigWarning constructor, and looks like this:

[Warning] /path/to/hie.yaml: ignoring unknown key "futureOption" in $.cradle.bios. The keys understood there are
"program", "shell", "dependency-program", "dependency-shell", "with-ghc".

Duplicate keys are still rejected, same as before.

I left the existing YAML types alone, so nothing that uses their constructors breaks. Two things worth flagging:

  • There's a new constructor on Log, in case something downstream matches on it exhaustively.
  • aeson >=2 is now required. There's no build plan with older versions on the GHCs we support anyway, so the CPP
    for them is gone.

For tests, I added parser tests for an unknown key in a cabal section and for unknown keys tucked inside a
multi cradle (one in a component, one in bios). They check that the config still parses to the right thing,
that the expected warnings come out, and that a normal config gives no warnings at all. I also tried the
hie-bios executable on a hie.yaml with a made-up key: on master it fails with
Unexpected keys ["futureOption"], and with this change it loads fine and shows the warning above with -v.

Happy to change the shape of the API if you'd rather expose this differently.

Unknown keys in the cabal, stack and bios sections of hie.yaml used to
make parsing fail, so adding a new optional key meant older versions of
hie-bios (and so HLS) couldn't read the file at all.

The parsers now ignore unknown keys. A separate pass over the YAML
value, using the same lists of known keys, reports them as
ConfigWarnings, with where in the file they were found. The new
readConfigWithWarnings returns these alongside the config, readConfig
keeps its type and ignores them, and loading a cradle logs each one as
a warning.

Fixes haskell#344
@mergify

mergify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, couple of nitpicks, otherwise very nice improvement, thank you very much!

Comment thread src/HIE/Bios/Types.hs Resolved
Comment thread src/HIE/Bios/Config.hs Resolved
Comment thread src/HIE/Bios/Config/YAML.hs Resolved
Comment thread src/HIE/Bios/Config/YAML.hs Resolved
Describe where unknown keys were found with a JSONPath, so that list
positions are indices rather than strings and warnings show the
location the same way aeson's own errors do, e.g. $.cradle.multi[0].

hie-bios can't be built with aeson < 2 on any supported GHC, so require
aeson >= 2 and remove the CPP for older versions. Keys no longer need to
be converted to strings.

Use prettyprinter's plural in the log message.

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much!

@fendor
fendor merged commit 1da3793 into haskell:master Nov 24, 2026
74 of 76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Turn unknown fields in hie.yaml into warnings

2 participants