-
Notifications
You must be signed in to change notification settings - Fork 310
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
Use sane fallbacks when reading empty files #3874
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a rather big change, and because File.readValue()
can now return null, the API is harder to use.
Therefore, I would propose an alternative approach: I wonder if it is worth the effort to check for empty files globally. I would argue that in most places an empty input file is just invalid and should be treated as if it contained syntactically wrong JSON or YAML. Only in special places we may want to be more lenient, e.g. when optional configuration files are involved.
So to distinguish between these cases, there could be a strict readValue()
function behaving as before (maybe with improved error logging that mentions an empty file), and a new readValueOrDefault()
function. The latter would do the empty check and return the default value if necessary. Then the caller can decide which variant to use, but would not have to bother with null values and more complex error handling.
One "problem" is that there is not "the default value", but it'd need to be configurable, so basically a configurable value to return instead of I'll play around with the idea, though. |
I also gave this some though again, and I actually believe it's not "most places". Basically, all configuration files are ok to be empty, but the result files are not. So it's rather 50/50 or so.
Please note that there are no mandatory configuration files per se.
What I dislike about that approach is that you're not forced / reminded to make that choice for all current uses in the code base, so you might miss to call More opinions from others? |
Fixes #3861. Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io>
7ff4083
to
4d103f5
Compare
@oss-review-toolkit/kotlin-devs I'm unsure how to proceed here. On the one hand I like the fact that all callers of Any more opinions here? |
To move things forward, I've split out a more minimal fix using @oheger-bosch's proposal: #3926 |
Fixes #3861.
Signed-off-by: Sebastian Schuberth sebastian.schuberth@bosch.io