ashald / EnvFile

EnvFile 3.x is a plugin for JetBrains IDEs that allows you to set environment variables for your run configurations from one or multiple files.
MIT License
533 stars 125 forks source link

EnvFile fails to parse well-formed yaml files #213

Open cmmoran opened 1 year ago

cmmoran commented 1 year ago

The yaml spec supports strings with or without single or double quotes. The following are considered identical:

Sample String
"Sample String"
'Sample String'

EnvFile can read yaml files as environment definitions. When EnvFile does so, it assumes all values for keys will be string. This may not necessarily be the case. For example, a trivial application may have a config file:

foo: bar
bar: 42

EnvFile will be unable to parse this yaml because bar will resolve as an integer and a resulting ClassCastException will be thrown.

Note: This exception is insidious because if the IDE was attempting to execute a Run Configuration when this exception occurred, the associated Toolbar button in the JetBrains IDE will be greyed out until the IDE is restarted

The trivial application developer(s) could be required to specify a separate config file just for EnvFile to be able to parse:

foo: bar
bar: "42"

This yaml would be properly read by EnvFile and provide the foo and bar environment variables at runtime.

This feels like a less-optimal solution. It requires maintaining two nearly identical configuration files when one can (and arguably should) be sufficient. It seems reasonable that EnvFile properly read a yaml file and attempt a gentle coercion (if possible) by simply attempting String.valueOf on the parsed yaml values. This will yield the expected Map<String,String> for EnvFile to use.