Skip to content

fix: Wrap weasyprint to catch exceptions#6728

Merged
rjsparks merged 6 commits intoietf-tools:mainfrom
pselkirk:fix-6324
Dec 27, 2023
Merged

fix: Wrap weasyprint to catch exceptions#6728
rjsparks merged 6 commits intoietf-tools:mainfrom
pselkirk:fix-6324

Conversation

@pselkirk
Copy link
Copy Markdown
Contributor

@pselkirk pselkirk commented Dec 3, 2023

Fixes #6324

@rjsparks
Copy link
Copy Markdown
Member

rjsparks commented Dec 5, 2023

Per real-time discussion - try using mock in the test.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f3a574c) 88.78% compared to head (26cc393) 88.80%.
Report is 2 commits behind head on main.

❗ Current head 26cc393 differs from pull request most recent head 3421ea4. Consider uploading reports for the commit 3421ea4 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6728      +/-   ##
==========================================
+ Coverage   88.78%   88.80%   +0.01%     
==========================================
  Files         285      285              
  Lines       40324    40286      -38     
==========================================
- Hits        35800    35774      -26     
+ Misses       4524     4512      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread ietf/doc/views_doc.py

pdf = doc.pdfized()
try:
pdf = doc.pdfized()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when this fails, it's after a fairly long timeout - I wonder if two timeouts will take us past the cloudflare timeout window?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a log to indicate how often a retry occurs? (Assuming that general failures are also logged, this would let us evaluate whether it's worth trying a second time)

Longer term, this would be a candidate to make into an async response and defer to celery.

Comment thread ietf/templates/doc/weasyprint_failed.html Outdated
Comment thread ietf/doc/views_doc.py Outdated
pdf = doc.pdfized()
try:
pdf = doc.pdfized()
except URLFetchingError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we've seen it throw, but I don't want it to emit some other exception and float it all the way back to a 5xx crash either. I think a general catch here, logging the error, and returning a "something went wrong, and someone will be looking into it. please try again later" message would be better?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also suggest not bubbling weasyprint dependencies up into the view. The pdfize() method should really handle those and raise its own error class (or classes if it needs to distinguish, say, temporary from permanent problems or other classifications).

Comment thread ietf/doc/views_doc.py Outdated
except URLFetchingError as exception:
return render(request, "doc/weasyprint_failed.html",
dict(error=f'{type(exception).__name__}: {exception}'),
status=504)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While 504 here is one technically correct to represent the situation , the key point of the issue is to not return any 5xx.

I would suggest a 200.

Copy link
Copy Markdown
Member

@jennifer-richards jennifer-richards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small (but I think important) nit.

Comment thread ietf/doc/views_doc.py Outdated
return render(request, "doc/weasyprint_failed.html",
dict(error=f'{type(exception).__name__}: {exception}'),
status=504)
except:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be except Exception - a bare except catches low-level non-Exception interruptions that shouldn't normally be caught without re-raising.

@rjsparks rjsparks merged commit 748bcc3 into ietf-tools:main Dec 27, 2023
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrap weasyprint to catch exceptions

3 participants