mjul / docjure

Read and write Office documents from Clojure
MIT License
622 stars 129 forks source link

Exception on reading a value from cell with error #27

Open nidu opened 9 years ago

nidu commented 9 years ago

Hello. When i'm reading a value from a cell with an error using read-cell i get the following exception:

IllegalArgumentException No method in multimethod 'read-cell-value' for dispatch value: 5  
clojure.lang.MultiFn.getFn (MultiFn.java:160)

Apparently that's because read-cell-value doesn't handle Cell/CELL_TYPE_ERROR. Is it a bug or should i treat erroneous cells differently?

mjul commented 9 years ago

Various people have mentioned error cell handling in previous issues and pull requests (e.g. pull request #11). Some people want the errors ignored, other want them replaced by a symbol and other clients may have yet other needs.

So, until now I preferred to just let the errors bubble up to the application.

If you can think of a way to provide pluggable error-handling strategies (for example to silent return error cells as blank, nil or :error) I would be happy to accept a pull request.

Maybe it can be done inside the existing multi-method design.

Another possibility is to move towards more of a state-machine approach so the POI object that is passed to the docjure functions is wrapped in a Clojure data structure which could then also include error handling strategies as higher-order function(s).

For a 2.0 release I prefer the latter, as it would also provide a good basis for making the text formatting stuff less imperative and more functional.

How do you propose to solve it?

nidu commented 9 years ago

It looks like it really can be done in multi-method design by just adding a handler for Cell/CELL_TYPE_ERROR. What about returning some kind of record with brief error info? It won't overlap with other cell types. Returning :error or nil can be not enough for a particular task if read-cell aims to satisfy all reading needs.