본문으로 건너뛰기
Skillpedia
PDF, Word, 슬라이드7.8k · #12914

pdf-debug-unbuffered

하는 일

이 스킬은 모호한 메시지로 실패하는 Python PDF 스크립트를 디버깅하는 요령입니다. 코드가 멈추는데 쓸모 있는 이유가 나오지 않는 사람에게 맞습니다.

사용하는 경우

  • ✓Python PDF 스크립트가 일반적인 알 수 없는 오류 메시지로 실패할 때.
  • ✓스크립트가 소리 없이 실패하고 트레이스백이 나오지 않는 경우.
  • ✓PDF 코드에서 글꼴, import 또는 파일 경로 문제가 있다고 의심될 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-debug-unbuffered/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-debug-unbuffered/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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

  1. -u flag: Forces Python to run in unbuffered mode, ensuring output (including errors) is flushed immediately rather than held in buffers that may be lost on crash
  2. 2>&1: Redirects stderr to stdout so both streams are captured together
  3. head: 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 -u flag 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로 출력을 제한하는 이유는 무엇인가요?

가장 중요한 오류 줄이 위쪽에 남아 읽기 쉬워지기 때문입니다.

어떤 종류의 오류를 찾을 수 있나요?

가이드는 누락된 import, 파일 경로 문제, 글꼴 등록 문제, 자원 한도를 언급합니다.

상세 정보

작성자의 원본 설명

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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬