harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
37 stars 30 forks source link

Handle errors when calculating reading length; fixes #1922 #1923

Closed lizadaly closed 1 year ago

lizadaly commented 1 year ago

There's a subtle bug somewhere in the code that reserializes annotations in cases where it's possible to add a link annotation inside another tag and end up with the serializer trying to output:

<a href="..."><span>I'm unclosed for some reason</a></span>

As a consequence, any code that called this (either the docx export or the reading length calculation) would stop at this point due to an uncaught exception.

The problem is something introduced by our code, not due to bad markup in the original. But in practice I think it doesn't matter if we output <a href=""><span>I'm unclosed</a></span> because both real browsers and the docx export code can deal with this fine.

This PR also more strongly guards against uncaught exceptions in the serialization code in the context of calculating reading length. This calculation is not mission-critical and so there's no particular reason we need to be notified nor that the user should be prevented from continuing. Unknown errors will still otherwise propagate during exports, because we want to know about those. Lastly, the correct behavior when skipping calculations due to errors is to report 0 here, because a value of None means it will try to recalculate every time, even if the content is unchanged.

codecov-commenter commented 1 year ago

Codecov Report

Merging #1923 (9312d87) into develop (d43f586) will decrease coverage by 0.12%. The diff coverage is 50.00%.

@@             Coverage Diff             @@
##           develop    #1923      +/-   ##
===========================================
- Coverage    77.02%   76.90%   -0.12%     
===========================================
  Files           58       58              
  Lines         6773     6795      +22     
===========================================
+ Hits          5217     5226       +9     
- Misses        1556     1569      +13     
Impacted Files Coverage Δ
web/main/models.py 73.97% <25.00%> (-0.04%) :arrow_down:
web/main/export.py 91.26% <66.66%> (-1.30%) :arrow_down:
web/main/admin.py 70.87% <0.00%> (-1.19%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.