pingcap / pingcap/tidb

Exception type too broad in error handling

Open
#69,342 0 comments 0 reactions 0 assignees View on GitHub
contribution
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### Description
Some `except` clauses catch overly broad exception types (e.g., bare `except:` or `except Exception:`), which can accidentally swallow important errors like `KeyboardInterrupt` or `SystemExit`.

### Example
```python
# Problematic:
try:
do_something()
except: # catches EVERYTHING including KeyboardInterrupt
pass

# Better:
try:
do_something()
except ValueError as e:
logger.warning(f"Value error: {e}")
```

### Expected Behavior
Exception handlers should catch only the specific exceptions they know how to handle.

### Impact
- Makes it impossible to interrupt the program with Ctrl+C in some cases
- Hides unexpected errors that should be investigated
- Makes debugging significantly harder

### Suggested Fix
Replace broad `except` clauses with specific exception types wherever possible.

Contributor guide

Open the contributing guide

Research direction

The issue does not name any files, tests, or entry points, and its examples use Python `except` clauses while TiDB is a Go repository. First verify whether the reported pattern exists in the Go source and identify the affected locations; completion would require replacing only handlers whose intended exception scope is established and running the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, databases
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.