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

Allow empty arrays in proxy #127

Closed
acavalli-lunalabs opened this issue Dec 6, 2023 · 7 comments
Closed

Allow empty arrays in proxy #127

acavalli-lunalabs opened this issue Dec 6, 2023 · 7 comments
Assignees

Comments

@acavalli-lunalabs
Copy link

I have the following hocon config file:

database: {
  global: {
    volumes: []
  }
}

If the volumes array is empty, i get the following error when I try to read globalCfg.getVolumes(); :

org.github.gestalt.config.exceptions.GestaltException: Failed to get proxy config while calling method: volumes in path: database.global.

I noticed that the class ProxyInvocationHandler inside ProxyDecoder.java does not have any value related to null properties and empty array properties.

@credmond-git
Copy link
Collaborator

Thanks for the bug report, generally gestalt fails if there is no data.
But i will try and make it a little more flexible to meet your needs.

@cavallium
Copy link

Yes, but in some formats, like hocon, an array with 0 elements is different than "null", it's impossible to get that property even if it's valid

@credmond-git credmond-git self-assigned this Dec 7, 2023
credmond-git added a commit that referenced this issue Dec 8, 2023
@credmond-git
Copy link
Collaborator

credmond-git commented Dec 8, 2023

Gestalt supports loading from 7 different formats, and has the capability to merge them. So we load each format, but then convert it into an internal representation. Unfortunately, From there we lose some of the special properties of each format.

I have added a new configuration flag treatEmptyCollectionAsErrors you can set on the builder. Please set this to false, to get your desired behavior. By default Gestalt will treat empty (null, size 0) collections as an error. By setting this to false, if there is an empty collection it will simply return an empty collection.

Hopefully this will resolve the issue. But i haven't tested specifically with a proxy object, but only with a list, set and array.

Once this is released please let me know if this works for you.

credmond-git added a commit that referenced this issue Dec 8, 2023
…ned instead of errors. #127 (#130)

feat: Add configuration option to allow empty collections to be returned instead of errors. #127
@cavallium
Copy link

cavallium commented Dec 8, 2023

It doesn't work on empty arrays. Attempting to get the empty array causes the following error:

org.github.gestalt.config.exceptions.GestaltException: Failed getting config path: database, for class: it.cavallium.rockserver.core.config.DatabaseConfig
 - level: MISSING_VALUE, message: Array on path: database.global.volumes, has no value attempting to decode Array
 - level: ERROR, message: Decoding object : GlobalDatabaseConfig on path: database.global.volumes, field volumes results in null value

The config looks like this:

database: {
  global: {
    volumes: []
  }
}

@cavallium
Copy link

If I set .setTreatNullValuesInClassAsErrors(false), it still doesn't help:

org.github.gestalt.config.exceptions.GestaltException: Failed to get cached object from proxy config while calling method: volumes with type: class [Lit.cavallium.rockserver.core.config.VolumeConfig; in path: database.global.
	at org.github.gestalt.core/org.github.gestalt.config.decoder.ProxyDecoder$ProxyCacheInvocationHandler.invoke(ProxyDecoder.java:194)
	at jdk.proxy2/jdk.proxy2.$Proxy8.volumes(Unknown Source)

credmond-git added a commit that referenced this issue Dec 8, 2023
…be returned instead of errors. #127 (#130)"

This reverts commit 5d87229.
credmond-git added a commit that referenced this issue Dec 8, 2023
…will only be returned if a node has been defined, if the node doesnt exist it will still throw errors. #127
credmond-git added a commit that referenced this issue Dec 8, 2023
* feat: Allow empty collections to be returned instead of errors. They will only be returned if a node has been defined, if the node doesnt exist it will still throw errors. #127
@credmond-git
Copy link
Collaborator

credmond-git commented Dec 8, 2023

Can you please try version 0.24.2 and let me know if it fixes the issue for you.

@cavallium
Copy link

It works, thanks!

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

3 participants