Pular para o conteúdo
Skillpedia
PDF, Word e slides7,8 mil · #12914

pdf-debug-unbuffered

O que ela faz

Esta skill é um truque de depuração para scripts Python de PDF que falham com mensagens vagas. É para pessoas cujo código de PDF para e não mostra um motivo útil.

Quando usar

  • ✓Quando um script Python de PDF falha com uma mensagem genérica de erro desconhecido.
  • ✓Quando o script parece falhar em silêncio e nenhum traceback aparece.
  • ✓Quando suspeito de uma fonte, importação ou caminho de arquivo ausente no código do PDF.

Link da skill

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

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-debug-unbuffered/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Meu script Python de PDF falha com uma mensagem que não diz nada útil. Por favor, execute-o para que possamos ver o erro real.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

A IA executa o script com a flag de saída sem buffer e combina a saída de erro com a saída normal, depois lê as primeiras linhas para encontrar o traceback.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do 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
Perguntas frequentes

O que faz a flag de saída sem buffer?

Ela faz o Python enviar a saída imediatamente, então as mensagens não se perdem se o programa travar.

Por que limitar a saída com head?

Limitar a saída mantém as linhas de erro mais importantes no topo, onde são fáceis de ler.

Que tipos de erro ela revela?

O guia menciona importações ausentes, problemas de caminho de arquivo, falhas de registro de fontes e limites de recursos.

Detalhes

Descrição original do autor

Debug Python PDF generation errors by using unbuffered output and stderr inspection to reveal actual tracebacks

repo: HKUDS/AgentPilot

Popularidade

Estrelas no GitHub
7,8 mil
Posição no ranking
#12914
Licença
MIT
Atualizada em
01/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas