elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.6k stars 24.63k forks source link

Improve exception message for bad `${ENV_VAR}` substitution in `elasticsearch.yml` #110858

Open DaveCTurner opened 2 months ago

DaveCTurner commented 2 months ago

Elasticsearch will interpolate environment variables into settings read from elasticsearch.yml:

cluster.name: ${ES_CLUSTER_NAME}

Any environment variables used in this way must be set, but the error for an unset environment variable is kinda opaque:

Exception in thread "main" java.lang.IllegalArgumentException: Could not resolve placeholder 'ES_CLUSTER_NAME'
    at org.elasticsearch.common.settings.PropertyPlaceholder.parseStringValue(PropertyPlaceholder.java:102)
    at org.elasticsearch.common.settings.PropertyPlaceholder.replacePlaceholders(PropertyPlaceholder.java:57)
    at org.elasticsearch.common.settings.Settings$Builder.replacePropertyPlaceholders(Settings.java:1314)
    at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:56)
    at org.elasticsearch.common.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:110)
    at org.elasticsearch.common.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:54)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
    at org.elasticsearch.cli.Command.main(Command.java:50)
    at org.elasticsearch.launcher.CliToolLauncher.main(CliToolLauncher.java:64)

Could we mention in this message that it relates to an environment variable mentioned in elasticsearch.yml which is not set?

elasticsearchmachine commented 2 months ago

Pinging @elastic/es-core-infra (Team:Core/Infra)