pdf-debug-unbuffered
できること
このスキルは、分かりにくいメッセージで失敗するPythonのPDFスクリプトをデバッグするための工夫です。コードが何の役にも立たない理由を示さずに止まる人向けです。
使う場面
- ✓PythonのPDFスクリプトが、一般的な原因不明のエラーメッセージで失敗するとき。
- ✓スクリプトが何も表示せずに失敗しているように見えるとき。
- ✓PDFのコードにおいて、フォント、インポート、ファイルパスの問題を疑うとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-debug-unbuffered/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“PythonのPDFスクリプトが、役に立たないメッセージで失敗します。本当のエラーが見えるように実行してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIは、バッファリングしないフラグを付けてスクリプトを実行し、エラーの出力と通常の出力を組み合わせ、トレースバックを探して先頭の数行を読みます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)を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
よくある質問
バッファリングしないフラグは何をしますか?
Pythonが出力をすぐに送るので、プログラムがクラッシュしてもメッセージが失われないようにします。
なぜheadで出力を制限するのですか?
出力を制限すると、重要なエラーの行が先頭に残り、読みやすくなるからです。
どんな種類のエラーが分かりますか?
インポートの欠落、ファイルパスの問題、フォント登録の問題、リソースの制限などです。
詳細
作者による元の説明
Debug Python PDF generation errors by using unbuffered output and stderr inspection to reveal actual tracebacks
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12914
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
agentpilot
7.8kエージェントが、作業を準備し、変更案を提案してテストし、評価するAgentPilotのループを実行することで、プロジェクトを段階的に改善できるよう支援します。
openspace
7.8kエージェントが、スキルを保存し取り出すツールであるOpenSpaceをセットアップし、MCPを通じてAIアプリに接続できるよう支援します。
rsi-arena
7.8kエージェントが、AIMEやTerminal-Benchなどの標準的なAIベンチマークテストをセットアップして実行し、異なる改善方法を比較できるよう支援します。
experiment-guide
7.8kエージェントが、プログラムを改善する方法を調べる間に、小さな実験を計画し、その結果を読み、発見を記録できるよう支援します。
似ているスキル
feishu-doc
394kテキスト、画像、表を含むFeishuのクラウドドキュメントを、ドキュメントツールを使って読み、作成し、編集するようエージェントを支援します。
feishu-drive
394kボットと共有されたFeishuのクラウドフォルダ内のファイルを閲覧、整理、コメントできるようエージェントを支援します。
feishu-perm
394kFeishuのファイルにアクセスできる人を確認し、変更するようエージェントを支援します。依頼を満たす最小の権限を選びます。