Repository navigation
Warn about unknown keys in hie.yaml instead of failing - #534
Merged
Merged
Conversation
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
Contributor
|
This pull request is merged. |
fendor
approved these changes
Nov 23, 2026
fendor
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, couple of nitpicks, otherwise very nice improvement, thank you very much!
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
approved these changes
Nov 24, 2026
fendor
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, thank you very much!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #344.
At the moment, if
hie.yamlhas a key hie-bios doesn't recognise in thecabal,stackorbiossection,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 aJSONPathsayingwhere the key was, like
$.cradle.biosor, 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 exportedConfigWarningfromHIE.Bios.Config.readConfighas the same type as before; it just ignores unknown keys nowinstead of failing. When a cradle gets loaded, each warning is logged at
Warninglevel through a newLogConfigWarningconstructor, and looks like this: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:
Log, in case something downstream matches on it exhaustively.aeson >=2is now required. There's no build plan with older versions on the GHCs we support anyway, so the CPPfor them is gone.
For tests, I added parser tests for an unknown key in a
cabalsection and for unknown keys tucked inside amulticradle (one in a component, one inbios). 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-biosexecutable on ahie.yamlwith a made-up key: on master it fails withUnexpected 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.