policies: improve recording of error messages during policy process
This commit is contained in:
parent
f8b4b92e8d
commit
4f28a89e63
|
@ -55,6 +55,10 @@ class PolicyEvaluator(BaseEvaluator):
|
||||||
|
|
||||||
def handle_error(self, exc: Exception, expression_source: str):
|
def handle_error(self, exc: Exception, expression_source: str):
|
||||||
"""Exception Handler"""
|
"""Exception Handler"""
|
||||||
|
# So, this is a bit questionable. Essentially, we are edit the stacktrace
|
||||||
|
# so the user only sees information relevant to them
|
||||||
|
# and none of our surrounding error handling
|
||||||
|
exc.__traceback__ = exc.__traceback__.tb_next
|
||||||
raise PolicyException(exc)
|
raise PolicyException(exc)
|
||||||
|
|
||||||
def evaluate(self, expression_source: str) -> PolicyResult:
|
def evaluate(self, expression_source: str) -> PolicyResult:
|
||||||
|
|
|
@ -15,6 +15,7 @@ from authentik.policies.models import PolicyBinding
|
||||||
from authentik.policies.types import PolicyRequest, PolicyResult
|
from authentik.policies.types import PolicyRequest, PolicyResult
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
|
TRACEBACK_HEADER = "Traceback (most recent call last):\n"
|
||||||
|
|
||||||
|
|
||||||
def cache_key(binding: PolicyBinding, request: PolicyRequest) -> str:
|
def cache_key(binding: PolicyBinding, request: PolicyRequest) -> str:
|
||||||
|
@ -85,7 +86,11 @@ class PolicyProcess(Process):
|
||||||
except PolicyException as exc:
|
except PolicyException as exc:
|
||||||
# Either use passed original exception or whatever we have
|
# Either use passed original exception or whatever we have
|
||||||
src_exc = exc.src_exc if exc.src_exc else exc
|
src_exc = exc.src_exc if exc.src_exc else exc
|
||||||
error_string = "".join(format_tb(src_exc.__traceback__)) + str(src_exc)
|
error_string = (
|
||||||
|
TRACEBACK_HEADER
|
||||||
|
+ "".join(format_tb(src_exc.__traceback__))
|
||||||
|
+ str(src_exc)
|
||||||
|
)
|
||||||
# Create policy exception event
|
# Create policy exception event
|
||||||
self.create_event(EventAction.POLICY_EXCEPTION, message=error_string)
|
self.create_event(EventAction.POLICY_EXCEPTION, message=error_string)
|
||||||
LOGGER.debug("P_ENG(proc): error", exc=exc)
|
LOGGER.debug("P_ENG(proc): error", exc=exc)
|
||||||
|
|
Reference in New Issue