Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor throws exception if underlying Config is invalid #187

Open
BittnerBarnabas opened this issue Oct 21, 2023 · 3 comments
Open

Comments

@BittnerBarnabas
Copy link

BittnerBarnabas commented Oct 21, 2023

Trying to use the component in an electron app, with specifying the JSON schema.

What I expect is that I can create the store with a potentially invalid underlying config, but when I call store.get(key) an exception should be thrown that the config is not valid.

What happens currently is that an exception is thrown from the constructor, as it seems there's no way to disable validation when the object is created: https://github.com/sindresorhus/conf/blob/main/source/index.ts#L133 . Currently, this makes it impossible to gracefully fix the config, the only option is to nuke the whole thing with clearInvalidConfig which will make users really mad that they lose their whole config. <- just tested this, doesn't work 😞

Example:
config.json contents:

{ "myKey": "myValue" }

Code:

store = new ElectronStore({
        schema: {
            myKey: {
                type: 'boolean',
            },
        },
    })

This throws an exception right away Error: Config schema violation: 'myKey' must be boolean .

@ParticleG
Copy link

Same issue

@simondw
Copy link

simondw commented Feb 13, 2024

Same issue, would really like to be able to log / handle errors but still be able to create a Store and get values from other collections / properties within a collection which do pass validation

@tim661811
Copy link

tim661811 commented Mar 4, 2024

This issue sounds similar to #173. I'm really hoping we can get this sorted, and see this meaningful improvement included in this library. Unfortunately, that issue has already been inactive since the beginning of 2023

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

No branches or pull requests

4 participants