From dcb93ad620d2b1ba644ade8f7659925891c11c5e Mon Sep 17 00:00:00 2001 From: anaslimem Date: Sat, 21 Feb 2026 03:32:49 +0100 Subject: [PATCH] Improve Error Handling in CodeChunker --- src/chonkie/chunker/code.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chonkie/chunker/code.py b/src/chonkie/chunker/code.py index 2cd3b254a..93b821148 100644 --- a/src/chonkie/chunker/code.py +++ b/src/chonkie/chunker/code.py @@ -348,7 +348,8 @@ def chunk(self, text: str) -> list[Chunk]: logger.debug(f"Using configured language: {self.language}") try: - assert self.parser is not None, "Parser is not initialized." + if self.parser is None: + raise RuntimeError("Parser failed to initialize. Language detection or initialization failed.") # Create the parsing tree for the current code tree: Tree = self.parser.parse(original_text_bytes) root_node: Node = tree.root_node