From 113ed0d7de6d99cf7d505a378ee7ddd7c7d29131 Mon Sep 17 00:00:00 2001 From: Victor Petrovykh Date: Fri, 9 Feb 2024 13:39:57 -0500 Subject: [PATCH] Expose the error details field. (#479) Error details get exposed as `_details` property. --- edgedb/errors/_base.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/edgedb/errors/_base.py b/edgedb/errors/_base.py index 675ef567..cd1d7f79 100644 --- a/edgedb/errors/_base.py +++ b/edgedb/errors/_base.py @@ -125,6 +125,11 @@ def _hint(self): # not a stable API method return self._read_str_field(FIELD_HINT) + @property + def _details(self): + # not a stable API method + return self._read_str_field(FIELD_DETAILS) + def _read_str_field(self, key, default=None): val = self._attrs.get(key) if val: @@ -156,6 +161,7 @@ def __str__(self): self._line if self._line > 0 else "?", self._col if self._col > 0 else "?", self._hint or "error", + self._details, ) except Exception: return "".join( @@ -226,7 +232,7 @@ def _severity_name(severity): return 'PANIC' -def _format_error(msg, query, start, offset, line, col, hint): +def _format_error(msg, query, start, offset, line, col, hint, details): c = get_color() rv = io.StringIO() rv.write(f"{c.BOLD}{msg}{c.ENDC}{LINESEP}") @@ -278,6 +284,10 @@ def _format_error(msg, query, start, offset, line, col, hint): rv.write(f"{c.BLUE}{'':>{num_len}} │ " f"{c.FAIL}╰─{'─' * (size - 1)}^ {hint}{c.ENDC}") break + + if details: + rv.write(f"{LINESEP}Details: {details}") + return rv.getvalue()