Open minrk opened 5 months ago
Looking a bit more, since static_url and templates are fundamentally tied together, and due to the presence of error pages, I think perhaps ExtensionHandlerJinjaMixin
should be merged into ExtensionHandlerMixin
, and if the fallback path of super().get_template
is taken, static_url
and static_path
should come from super()
not from the mixin.
Perhaps the best fix is to apply static_url differently - i.e. instead of being an instance method on the Handler objects, place it into the Environment globals. Because static_url really is a property of the. I'm not sure of the backward-compatibility implications of switching to doing it that way, though.
Seeing this error even in a vanilla jupyterlab install when starting the terminal extension
[E 2024-10-30 17:57:51.925 ServerApp] Uncaught exception in write_error
Traceback (most recent call last):
File "/.virtualenvs/crosscompute/lib64/python3.12/site-packages/tornado/web.py", line 1298, in send_error
self.write_error(status_code, **kwargs)
File "/.virtualenvs/crosscompute/lib64/python3.12/site-packages/jupyter_server/base/handlers.py", line 739, in write_error
html = self.render_template("%s.html" % status_code, **ns)
...
File "/.virtualenvs/crosscompute/lib64/python3.12/site-packages/jupyter_server/extension/handler.py", line 118, in static_url
raise Exception(msg) from None
Exception: This extension doesn't have any static paths listed. Check that the extension's `static_paths` trait is set.
Description
Attempts to serve jupyter-server's default error pages from an
ExtensionHandlerMixin
handler fail with:if the extension doesn't have static_paths configured. If static_paths is configured and doesn't include serverapp's static_paths, it renders the template successfully, but fails to find any static files:
This is because
ExtensionHandlerMixin
specifies that static_paths is per-extension, but static_url is used when rendering error page templates which come from base JupyterHandler and shouldn't be affected by the extension's configuration (at least unless overridden explicitly).As it is now, essentially
ExtensionHandlerMixin
must always either:This is currently coming up in jupyter_server_terminals when accessing a terminal that has stopped, reported in https://discourse.jupyter.org/t/this-extension-doesnt-have-any-static-paths-listed/26524 (the real topic there is what's causing the error, but it revealed the bug in error handling). Looking at the code, I think
ExtensionHandlerMixin
shouldn't be used injupyter_server_terminals
, but I don't think it should be broken if it is used.I suspect the fix is to special-case the error templates to ensure JupyterHandler's static_url is called, and not the mixin's.
Reproduce
Create a test extension that raises an error:
Launch it with:
default URL hits the 404 above, resulting in:
Expected behavior
default error templates render for extension pages without needing to specify unused static_paths config.
Context
Troubleshoot Output
Command Line Output