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

Crashing on keys with dot #416

Open
KonradSwierczynski opened this issue Aug 21, 2023 · 1 comment
Open

Crashing on keys with dot #416

KonradSwierczynski opened this issue Aug 21, 2023 · 1 comment

Comments

@KonradSwierczynski
Copy link

Hey, I spotted strange behaviour when using keys with dots which is inconsistent and can crash validating config.

See example below:

const config = convict({
  test: {
    param: {
      doc: 'some nested parameter',
      format: String,
      default: 'foo',
    },
  },
});

// Example 1
config.load({ 'test.param': 'bar' });
config.validate({ allowed: 'strict' });  // passes validation
console.log(config.get('test.param'));  // prints out 'foo' - unexpected, since previous load should set the value or fail validation
// in this example the validate would throw an error, key with dot should not be treated as path

// Example 2
config.load({ 'someOther.param': 'baz' });
config.validate({ allowed: 'warn' });  // throws error - unexpected, should just print a warning

/* the error:
Uncaught Error: cannot find configuration param 'someOther.param'
    at walk ([...]/node_modules/convict/src/main.js:2:8321)
    at flatten ([...]/node_modules/convict/src/main.js:2:1400)
    at validate ([...]/node_modules/convict/src/main.js:2:2099)
    at Object.validate (/[...]/node_modules/convict/src/main.js:2:10481)
*/

I'm using convict in version 6.2.4 and node v18.17.0.

@paul-vd
Copy link

paul-vd commented Feb 15, 2024

Having the same issue, I'm trying to store react-intl messages in my config, but due to their naming I get the same failure, for example

messages: {
  doc: "Translated messages for current shop locale",
  format: Object,
  default: {
    "foo.bar": "bar",
  },
},

fails with Error: cannot find configuration param 'public.messages.foo.bar'

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

2 participants