-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Add ability to track the location of cells that raise casting exceptions #85
Conversation
Using a default implementation of castValue(…) with row and column numbers we can silently add the ability to record the location of any casting being done for logging purposes.
This is an example implementation of the newly modified Casting interface, which stores information about casting errors for later retrieval.
Hi @brunslo , thank you for your effort! here we need to improve our coverage more to be able to accept this PR |
Fix regression due to overzealous IDE.
Given that the original authors were open to logging location in Casting, it makes sense to reduce code duplication by adding the logging code directly to DefaultCasting. Logging is disabled by default and enabled with a boolean flag to the constructor. A new public method isErrorLoggingEnabled() is added, which indicates whether or not logging was enabled on creation. A new public method getErrors() is also added that returns details of any exception thrown during a cast, including the sheet, row, and column. This method throw an IllegalStateException when called on an instance without logging enabled. This ensures that a returned empty getErrors() List when logging is disabled is not misinterpreted to mean there were not casting exceptions thrown during unmarshaling. Existing tests for DefaultCasting now include a check to ensure that logging is disabled and that the expected IllegalStateException is thrown when attempting to call getErrors(). Another set of tests that interrogates the logging will be in a forthcoming commit.
I took the presumptive step to fold the logging additions into the I still have the |
Thank you @brunslo , I'll look at the code you made 🎉 |
merged @brunslo ! 🎉 |
With a backwards compatible change to the Casting interface it is simple to add the ability to log formatting errors found during the casting of values from the original workbook cells. The change adds a default method extending
castValue
which accepts row and column numbers along with the regular casting parameters. This change, coupled with the passing of already known row and column numbers inHSSFUnmarshaller
andPoijiHandler
into the few placescastValue
is called gives a light weight error location tracker for very little cost.An example of how this could be done is provided in the
LogCasting
class, which is provided as a simple proof of concept without tests.