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

[BUG] Environment variable substitution fails silently if "__format" parser is not supported #753

Open
KalleV opened this issue Dec 11, 2023 · 1 comment

Comments

@KalleV
Copy link

KalleV commented Dec 11, 2023

Describe the bug
Defining a custom-environment-variables.json file with "__format" definitions that do not match a supported parser leads to the configuration being silently ignored.

Example:

{
  "hostname": {
    "__name": "HOSTNAME",
    "__format": "string"
  }
}

Expected behavior
An error when attempting to use an unsupported parser.

Screenshots
N/A

Please tell us about your environment:

  • node-config version: 3.3.9
  • node-version: 20.x

Other information

Related code:

  • node-config/lib/config.js

    Lines 897 to 902 in 8c52ea2

    util.parseString = function (content, format) {
    const parser = Parser.getParser(format);
    if (typeof parser === 'function') {
    return parser(null, content);
    }
    };
  • node-config/lib/config.js

    Lines 1103 to 1113 in 8c52ea2

    if ('__name' in value && '__format' in value && typeof vars[value.__name] !== 'undefined' && vars[value.__name] !== '') {
    try {
    const parsedValue = util.parseString(vars[value.__name], value.__format);
    } catch(err) {
    err.message = '__format parser error in ' + value.__name + ': ' + err.message;
    throw err;
    }
    util.setPath(result, pathTo.concat(prop), parsedValue);
    } else {
    _substituteVars(value, vars, pathTo.concat(prop));
    }
@lorenwest
Copy link
Collaborator

Agreed it would be an improvement to either output an error message or throw an error if an unknown parser is specified.

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