pdf-debug-unbuffered
What it does
This skill is a debugging trick for Python PDF scripts that fail with vague messages. It is for people whose PDF code stops and shows no useful reason.
When to use it
- ✓When a Python PDF script fails with a generic unknown error message.
- ✓When the script seems to fail silently and no traceback appears.
- ✓When I suspect a missing font, import or file path in the PDF code.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-debug-unbuffered/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“My Python PDF script fails with a message that says nothing useful. Please run it so we can see the real error.”
5 new skills a week. 1 minute to read.
How it works
The AI runs the script with the unbuffered flag and combines the error output with the normal output, then reads the top lines to find the traceback.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
PDF Generation Debug Technique
When Python PDF libraries (reportlab, fpdf, etc.) fail with generic "unknown error" messages, the actual cause is often hidden due to output buffering or error swallowing. This skill provides a technique to expose the real traceback.
Core Technique
Run the Python script with the -u flag (unbuffered output) and pipe stderr through head to capture the actual error:
python -u your_script.py 2>&1 | head -100
Or more specifically, to focus on stderr:
python -u your_script.py 2>&1 | head -50
Why This Works
-uflag: Forces Python to run in unbuffered mode, ensuring output (including errors) is flushed immediately rather than held in buffers that may be lost on crash2>&1: Redirects stderr to stdout so both streams are captured togetherhead: Limits output to show the most relevant error messages at the top
Step-by-Step Debugging
Step 1: Identify the failing script
Locate the Python script that generates the PDF and is producing generic errors.
Step 2: Run with unbuffered output
python -u generate_pdf.py 2>&1 | head -100
Step 3: Analyze the traceback
Look for:
- Import errors (missing dependencies)
- File path issues (invalid paths, permission errors)
- Font registration problems (common with reportlab)
- Memory or resource constraints
Step 4: Fix the underlying issue
Address the specific error revealed in the traceback.
Step 5: Re-run normally
Once fixed, run the script without the debug flags to confirm it works:
python generate_pdf.py
Common Issues Revealed
| Symptom | Likely Cause |
|---|---|
| "unknown error" on PDF save | File path doesn't exist or no write permissions |
| Generic failure during build | Missing font files or font registration issues |
| Silent crash | ImportError for missing dependencies |
| Incomplete PDF | Script terminated early due to unhandled exception |
Alternative Approaches
If the above doesn't work, try:
# Capture full stderr to a file
python -u script.py 2> error.log
# Use Python's traceback module explicitly
python -c "import traceback; exec(open('script.py').read())" 2>&1
# Run with verbose import tracing
python -v -u script.py 2>&1 | head -200
Example: Debugging reportlab
# Before: Generic error
python create_checklist.py
# Output: "Error: unknown"
# After: Actual traceback
python -u create_checklist.py 2>&1 | head -50
# Output: "FileNotFoundError: [Errno 2] No such file or directory: '/fonts/Helvetica.ttf'"
Notes
- This technique applies to any Python script with opaque error messages, not just PDF generation
- The
-uflag is available in Python 2.7+ and all Python 3 versions - For production debugging, consider logging to a file instead of using
head
FAQ
What does the unbuffered flag do?
It makes Python send its output immediately, so messages are not lost if the program crashes.
Why limit the output with head?
Limiting the output keeps the most important error lines at the top where they are easy to read.
What kinds of errors does it reveal?
The guide mentions missing imports, file path problems, font registration issues and resource limits.
Details
Original description by the author
Debug Python PDF generation errors by using unbuffered output and stderr inspection to reveal actual tracebacks
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12914
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
feishu-doc
394kHelps your agent read, create, and edit Feishu cloud documents, including text, images, and tables, using the document tool.
feishu-drive
394kLets your agent browse, organize, and comment on files in a Feishu cloud folder that has been shared with the bot.
feishu-perm
394kHelps your agent check and change who can access a Feishu file, choosing the smallest permission that meets your request.