This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git


The following commit(s) were added to refs/heads/main by this push:
     new 812351a  Improve error reporting when an undefined route is used in a 
template
812351a is described below

commit 812351ab257f2350fe009a968a2d07ba23d3bd30
Author: Sean B. Palmer <[email protected]>
AuthorDate: Thu Apr 10 20:15:17 2025 +0100

    Improve error reporting when an undefined route is used in a template
---
 atr/util.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/atr/util.py b/atr/util.py
index 117d6fe..ffc0403 100644
--- a/atr/util.py
+++ b/atr/util.py
@@ -35,6 +35,7 @@ import aiofiles.os
 import asfquart
 import asfquart.base as base
 import asfquart.session as session
+import jinja2
 import pydantic
 import pydantic_core
 import quart
@@ -132,7 +133,15 @@ async def archive_listing(file_path: pathlib.Path) -> 
list[str] | None:
 
 def as_url(func: Callable, **kwargs: Any) -> str:
     """Return the URL for a function."""
-    return quart.url_for(func.__annotations__["endpoint"], **kwargs)
+    if isinstance(func, jinja2.runtime.Undefined):
+        _LOGGER.exception("Undefined route in the calling template")
+        raise base.ASFQuartException("Undefined route", 500)
+    try:
+        annotations = func.__annotations__
+    except AttributeError as e:
+        _LOGGER.error(f"Cannot get annotations for {func} (type: 
{type(func)})")
+        raise base.ASFQuartException(f"Cannot get annotations for {func} 
(type: {type(func)})", 500) from e
+    return quart.url_for(annotations["endpoint"], **kwargs)
 
 
 @contextlib.asynccontextmanager


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to