Skip to content

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

@KalleV

Description

@KalleV

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));
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions