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

Environment Variables are somewhat case sensitive...? #153

Closed
brainbytes42 opened this issue Feb 28, 2024 · 4 comments
Closed

Environment Variables are somewhat case sensitive...? #153

brainbytes42 opened this issue Feb 28, 2024 · 4 comments
Assignees

Comments

@brainbytes42
Copy link

brainbytes42 commented Feb 28, 2024

Hi,

I came across a weird situation, where I have had two environment variables with the same key, but different capitalizations (prefix or path is not relevant, for example PREFIX_A_B and PREFIX_a_B). So, obviously, this is not a correct environment and I will catch this case, but the Exception was quite misleading at first...

Caused by: org.github.gestalt.config.exceptions.GestaltConfigurationException: Failed to load configs from source: envVars
 - level: ERROR, message: Mismatched path lengths received for path: context.mode, this could be because a node is both a leaf and an object
	at org.github.gestalt.config.GestaltCore.validateLoadResultsForErrors(GestaltCore.java:203) ~[gestalt-core-0.24.6.jar:?]
	at org.github.gestalt.config.GestaltCore.loadConfigs(GestaltCore.java:129) ~[gestalt-core-0.24.6.jar:?]
	at org.github.gestalt.config.GestaltCache.loadConfigs(GestaltCache.java:38) ~[gestalt-core-0.24.6.jar:?]

Maybe something like ' for path x.y.z there were different values in same source' or something like that would be better? And if values are the same, just merge both...?

(Hint for debugging: In IntelliJ, if you specify the environment, duplicate variables even with different cases will get stripped. But with ProcessBuilder, it's possible to create such malformed environments.)

Additional Note: my expectation of case-insensitivity comes from the first sentence of this paragraph:
https://github.com/gestalt-config/gestalt#getconfig-path-options

@credmond-git
Copy link
Collaborator

Since Gestalt supports multiple config sources that have varying cases we normalize all configs to lower case as we build an internal tree. The input sources such as Env Vars are case sensitive, but we create a path by tokenizing it and converting it to lower case. We need to enforce some limitations internally, such as we cant have duplicate nodes or a node can not be of multiple types, such as a leaf and a object.

I will check the documentation and see if i can make it more clear. The docs are already long and i didnt want to get to specific, but it may be needed.

Duplicate nodes

my.path = value1
my.path = value2

A path is multiple types, my.path has both a value making it a leaf, and a sub path making it a object. This is prevented.

my.path = value1
my.path.name = value2

Unfortunately, it is too difficult to check for similar values and merge them here, so i will leave it as an error.

This error covers both cases. I have updated the error message, it is still not great, and i will think about it a little more. but hopefully it is more clear, as i added the duplicate paths cause. It also includes the path to help with investigating.

Updated error:

Parsing path length errors for path: db, there could be several causes such as: duplicate paths, or a node is both a leaf and an object

@credmond-git
Copy link
Collaborator

I am not creating a new release right now. So there is no way to validate this for now.

@credmond-git credmond-git self-assigned this Feb 28, 2024
@credmond-git
Copy link
Collaborator

I also updated the config-tree documentation to be a little more clear about when it converts to lower case and the errors that can occur.

@brainbytes42
Copy link
Author

The updated message will help a lot already, I think. 👍

[For the merging, in my specific case I now scan the ProcessBuilder's Environment Map for any key, that is equalIgnoreCase to one I'm creating at runtime, and then use the existing keys exact spelling, so that it matches all possible cases, the user might have entered for the main process. This prevents me from having this weired state... ]

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