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

inconsistent behaviour when dealing with sealed config #549

Open
1 task done
snrbrnjna opened this issue May 3, 2019 · 0 comments
Open
1 task done

inconsistent behaviour when dealing with sealed config #549

snrbrnjna opened this issue May 3, 2019 · 0 comments

Comments

@snrbrnjna
Copy link

I'm submitting a ...

  • bug report
  • [ ] feature request
  • [ ] support request or question => Please do not submit support request or questions here, see note at the top of this template.

What is the current behavior?

When the config is sealed, it reacts inconsistently on manipulations with util.setModuleDefaults:

  1. TypeError when it tries to add a new config param
  2. No Error, but silently ignored nested default config params, when top level object existed before.

To reproduce Case 1):

const config = require('config');
config.util.setModuleDefaults('http', {useAgent: 'lala 42'});
config.get('http');
config.util.setModuleDefaults('http', {useAgent: 'lala 42', another: 'prop'});
> TypeError: Cannot define property another, object is not extensible

To reproduce Case 2):

const config = require('config');
config.util.setModuleDefaults('http', {obj: {}});
config.get('http');
config.util.setModuleDefaults('http', {obj: {prop: 'this default isn\'t set'}});

What is the expected behavior?

Perhaps it would help, if the setModuleDefault consistently crashes (with a meaningful error), when it is called on a sealed instance. Or only, but always, when there's already something defined under the specified moduleName.

The change introduced with #507 causes a lot problems in projects, where there are different modules using node-config each calling setModuleDefault. On module loading time, we query the different config params, hence later loaded modules with a node-config produce TypeError crashes or silently swalloed config params.

Perhaps another possibility to avoid these problems would be to seal only the used namespaces of the config object. that way, i can manipulate my moduleFoo namespace as long as it wasn't used.

Please tell us about your environment:

  • node-config version: 3.0.1
  • node-version: 10.15.2
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

1 participant