From 4358bbb28d647c9846e185cd6d1ea46bc1798c27 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 10 Nov 2026 23:03:40 +0000 Subject: [PATCH] Keep the original error when join() rejects a suffix join() turns any failure into JsonPointerException("Invalid suffix"). Raise it "from" the original exception so the underlying cause (e.g. a TypeError for a non-iterable suffix) shows up in tracebacks and is available as __cause__. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PewzpjhRBV84QNbKy9H564 --- jsonpointer.py | 4 ++-- tests.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jsonpointer.py b/jsonpointer.py index f54f637..00b9ba3 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -394,8 +394,8 @@ def join(self, suffix): suffix_parts = suffix try: return self.__class__.from_parts(chain(self.parts, suffix_parts)) - except Exception: - raise JsonPointerException("Invalid suffix") + except Exception as e: + raise JsonPointerException("Invalid suffix") from e def __truediv__(self, suffix): return self.join(suffix) diff --git a/tests.py b/tests.py index c1542d7..49d8c4e 100755 --- a/tests.py +++ b/tests.py @@ -216,6 +216,11 @@ def test_join(self): self.assertRaises(JsonPointerException, self.ptr1.join, 0) + def test_join_chains_original_error(self): + with self.assertRaises(JsonPointerException) as caught: + self.ptr1.join(0) + self.assertIsInstance(caught.exception.__cause__, TypeError) + def test_join_magic(self): ptr12a = self.ptr1 / self.ptr2 self.assertEqual(ptr12a.path, "/a/b/c/a/b")