Skip to content

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

Open

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

Activity

  1. lorenwest commented on Dec 11, 2023

    @lorenwest
    Collaborator

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

  2. markstos commented on Jan 7, 2025

    @markstos
    Collaborator

    @KalleV Would you like to contribute a PR for this? Otherwise, the issue is likely to stay open.

  3. jdmarshall commented on Apr 28, 2025

    @jdmarshall
    Collaborator

    I'm not sure how I feel about this feature, but this feels like an extension of strict mode

  4. jdmarshall commented on Jul 17, 2025

    @jdmarshall
    Collaborator

    There's a placeholder for this feature in lib/util.js

    https://github.com/node-config/node-config/blob/master/lib/util.js#L1303

  5. added this to the 5.0 milestone on Feb 22, 2026
  6. jdmarshall commented on Jul 10, 2026

    @jdmarshall
    Collaborator

    I've flagged this as a breaking change but it's a relatively small one as these things go. But I still might move it to 6.0

  7. modified the milestones: 5.0, 6.0 on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions