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

Review validation of configuration properties and associated error messages #653

Open
brenuart opened this issue Sep 20, 2021 · 0 comments
Assignees

Comments

@brenuart
Copy link
Collaborator

Rules:

  • Property must be validated eagerly by the corresponding setter method. An IllegalArgumentException should be thrown when the validation fails. A NullPointerException is currently thrown in most cases for not-null properties - an IllegalStateException should be used instead for consistency.

  • The exception message often reports the name of the property which is not required. When Joran fails to set a property it already builds an error message itself reporting which property failed. For example:

10:15:07,901 |-WARN in ch.qos.logback.core.joran.util.PropertySetter@1ffe63b9 - Failed to set property [encoding] to value "foo".  ch.qos.logback.core.util.PropertySetterException: java.lang.reflect.InvocationTargetException
	at ch.qos.logback.core.util.PropertySetterException: java.lang.reflect.InvocationTargetException
	at 	at ch.qos.logback.core.joran.util.PropertySetter.setProperty(PropertySetter.java:133)
	at 	at ch.qos.logback.core.joran.util.PropertySetter.setProperty(PropertySetter.java:98)
...
Caused by: java.lang.IllegalArgumentException: Unknown encoding foo
	at 	at net.logstash.logback.composite.CompositeJsonFormatter.setEncoding(CompositeJsonFormatter.java:337)
	at 	at net.logstash.logback.encoder.CompositeJsonEncoder.setEncoding(CompositeJsonEncoder.java:234)
	at 	... 25 common frames omitted

Adding the name of the property in the exception message requires to keep the error message in sync with the name of the corresponding setter method - this may fail in case of refactoring.

  • It may happen however the exception message must refer to one or more properties by their name. For instance:
Property [foo] cannot be used when property [bar] is set to "value".

In this case, property names must be enclosed between brackets ([...]) to follow the same Logback conventions.

Note: these rules apply to the validation of configuration properties. Other methods not directly used by Joran to set a property are free to use other conventions.

@brenuart brenuart self-assigned this Sep 21, 2021
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

1 participant