Skip to content

Config merging mishandles default values #1959

@katrinafyi

Description

@katrinafyi

generally, any option specified on the command line should have precedence over options in the toml file (which have precedence over the default values).

however, the fold_in! macro logic for merging two config structs is slightly flawed. this can cause an option specified at the command line to be deprioritised in favour of a toml config value.

the macro assumes that if the CLI has a default value for an argument, then that should be overridden by the .toml's value (if any). but that's not necessarily correct, because the user may have manually specified a CLI argument that happens to be equal to the default. in these cases, the CLI value should still take precedence over the toml file.

this bug will become more important if lychee wants to do more config file things. in particular, if lychee wants to process multiple config files with precedence between them.

mentioned in #1848

repro:

$ echo 'mode = "task"' > a.toml
$ echo 'https://mock.httpstatus.io/404' | cargo run -- - -v --mode color -c a.toml
     [404] https://mock.httpstatus.io/404 | Rejected status code (this depends on your "accept" configuration): Not Found

Issues found in 1 input. Find details below.

[stdin]:
- [ ] [404] https://mock.httpstatus.io/404 | Rejected status code (this depends on your "accept" configuration): Not Found

note that the mode = task from the config is used even though we specified mode = color on the command line. this is because color coincides with the default value. if you specify a different --mode argument (e.g. emoji), then the CLI value will be correctly used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions