Skip to content

fix: replace bare except with except Exception in types/base.py - #580

Open
KeloYuan wants to merge 1 commit into
feyninc:mainfrom
KeloYuan:fix/bare-except-improvements
Open

fix: replace bare except with except Exception in types/base.py#580
KeloYuan wants to merge 1 commit into
feyninc:mainfrom
KeloYuan:fix/bare-except-improvements

Conversation

@KeloYuan

@KeloYuan KeloYuan commented May 8, 2026

Copy link
Copy Markdown

Replaces bare except: with except Exception: in src/chonkie/types/base.py (line 82).

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling in embedding preview formatting to prevent unintended fallback behaviors and provide more precise error detection.

Copilot AI review requested due to automatic review settings May 8, 2026 13:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens exception handling in Chunk._preview_embedding() by replacing a bare except: with except Exception:, avoiding suppression of non-standard exceptions (e.g., KeyboardInterrupt, SystemExit) during embedding preview generation used in __repr__.

Changes:

  • Replace bare except: with except Exception: in _preview_embedding().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the exception handling in src/chonkie/types/base.py by replacing a bare except clause with except Exception. The reviewer suggests further refining this by catching specific exceptions to avoid suppressing unexpected internal errors, providing a more robust implementation in line with PEP 8 recommendations.

Comment thread src/chonkie/types/base.py
else:
return str(self.embedding)
except:
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While replacing a bare except: with except Exception: is an improvement as it avoids catching system-exiting exceptions (like KeyboardInterrupt), it is still considered a broad catch. For a more robust implementation, it is better to catch only the specific exceptions that are expected to occur during the formatting and indexing of the embedding, such as AttributeError, TypeError, ValueError, IndexError, and KeyError. This ensures that unexpected internal errors are not silently suppressed.

Suggested change
except Exception:
except (AttributeError, TypeError, ValueError, IndexError, KeyError):
References
  1. PEP 8 recommends catching specific exceptions whenever possible instead of using a broad except Exception: clause. (link)

@coderabbitai

coderabbitai Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a006c5c9-e82f-4864-ae6a-570e3d165e03

📥 Commits

Reviewing files that changed from the base of the PR and between 39d2ef3 and fe076a6.

📒 Files selected for processing (1)
  • src/chonkie/types/base.py

📝 Walkthrough

Walkthrough

The pull request narrows exception handling in the Chunk._preview_embedding() method by replacing a bare except clause with except Exception. This change prevents system-level exceptions like KeyboardInterrupt and SystemExit from triggering the embedding preview fallback.

Changes

Exception Handling Specificity

Layer / File(s) Summary
Error Handling Narrowing
src/chonkie/types/base.py
Exception handler in _preview_embedding() changed from bare except to except Exception, restricting which error types trigger the "<embedding>" fallback.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A catch clause gets precise,
No more catching what shouldn't be nice—
Exception now guards the way,
System exits live to fight another day! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing a bare except clause with except Exception in the specified file.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants