# Bug Fix: Broken Pipe Error in test.sh
## Issue
When running `./scripts/test.sh --skip-tests`, radon was throwing a `BrokenPipeError` during complexity analysis:
```
BrokenPipeError: [Errno 32] Broken pipe
```
This error occurred twice in the output, cluttering the results with Python tracebacks.
## Root Cause
The broken pipe error was caused by piping radon output to `head -n 50`:
```bash
uv run radon cc src/playwright_proxy_mcp -a -s | head -n 50
```
**What happened:**
1. Radon starts outputting complexity data
2. `head` reads the first 50 lines and then closes the pipe
3. Radon continues trying to write to the now-closed pipe
4. Operating system sends SIGPIPE signal
5. Python/radon throws `BrokenPipeError`
This is a common Unix pipe behavior - when the reading end closes, the writing end gets a broken pipe.
## Solution
Added error suppression to handle the broken pipe gracefully:
```bash
# Before (broken):
uv run radon cc src/playwright_proxy_mcp -a -s | head -n 50
# After (fixed):
uv run radon cc src/playwright_proxy_mcp -a -s 2>/dev/null | head -n 50 || true
```
**What this does:**
- `2>/dev/null` - Redirects stderr (including BrokenPipeError) to null
- `|| true` - Ensures the command always returns success (exit code 0)
## Changes Made
**File**: `/workspace/scripts/test.sh`
**Lines Modified**: 216 and 219
### Before
```bash
# Line 216
uv run radon cc src/playwright_proxy_mcp -a -s | head -n 50
# Line 219
HIGH_COMPLEXITY=$(uv run radon cc src/playwright_proxy_mcp -s | grep -E "^\s+[FMC]\s+\d+:\d+\s+\w+\s+-\s+[C-F]" || echo "")
```
### After
```bash
# Line 216
uv run radon cc src/playwright_proxy_mcp -a -s 2>/dev/null | head -n 50 || true
# Line 219
HIGH_COMPLEXITY=$(uv run radon cc src/playwright_proxy_mcp -s 2>/dev/null | grep -E "^\s+[FMC]\s+\d+:\d+\s+\w+\s+-\s+[C-F]" || echo "")
```
## Testing
### Verified Fix
```bash
# Test with skipped tests (original failing scenario)
./scripts/test.sh --skip-tests
# ✅ No broken pipe errors
# Test with full run
./scripts/test.sh --skip-duplication
# ✅ No broken pipe errors
# Verify no error traces
./scripts/test.sh --skip-tests 2>&1 | grep -E "(BrokenPipeError|Traceback)"
# ✅ No output (no errors found)
```
### Output Quality
The fix maintains the same user experience:
- ✅ Still shows first 50 lines of complexity analysis
- ✅ Still identifies high-complexity functions
- ✅ No error messages or tracebacks
- ✅ Clean, professional output
## Why This Approach
**Alternative approaches considered:**
1. **Remove `head` limit**: Would show all output (100+ lines), too verbose
2. **Capture to variable first**: More complex, uses more memory
3. **Use `grep` filtering only**: Doesn't limit total output
4. **Ignore SIGPIPE in Python**: Would require modifying radon itself
**Chosen approach benefits:**
- ✅ Simple and standard Unix pattern
- ✅ No code complexity increase
- ✅ Maintains desired output format
- ✅ Widely used solution for pipe issues
- ✅ No dependencies on external tools
## Impact
- **User Experience**: Clean output, no scary error messages
- **Functionality**: Unchanged - same information displayed
- **Performance**: No impact
- **Compatibility**: Works on all Unix-like systems
## Related Issues
This is a common pattern when piping to `head`, `less`, or other programs that may close pipes early. Similar fixes may be needed if adding more commands that pipe large outputs.
**Pattern to remember:**
```bash
# When piping to head/less/etc
command 2>/dev/null | head -n N || true
```
## Status
✅ **Fixed and Verified**
- No broken pipe errors in any test scenario
- Output quality maintained
- User experience improved