Pular para o conteúdo
Skillpedia
Código em geral7,8 mil · #12957

python-debug-pattern

O que ela faz

Esta skill dá ao agente de IA uma forma repetível de executar scripts Python e descobrir por que eles falham. É para quem precisa de detalhes claros de erro de um script.

Quando usar

  • ✓Quando um script Python falha e você vê apenas uma mensagem opaca.
  • ✓Quando um script grava em um arquivo e você precisa confirmar para onde ele foi.
  • ✓Quando você quer que a IA compare uma execução correta com uma execução com erro.

Link da skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-pattern/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/python-debug-pattern/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

“Execute meu script process_data e me diga exatamente por que ele falha, incluindo o erro completo.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

O agente executa o script com o stderr capturado e imprime o código de saída. Registra o diretório de trabalho e o caminho absoluto de qualquer arquivo que o script grave.

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

Texto original do autor, em inglês, direto do GitHub.

Python Debug Pattern

This skill provides a reusable pattern for debugging Python script execution failures. It ensures you capture actual tracebacks instead of opaque errors and verify the working directory before file operations.

Core Technique

1. Execute Python Scripts with Full Error Capture

When running Python scripts, always use this command pattern to surface actual tracebacks:

python3 script.py 2>&1 ; echo Exit code: $?

Why this works:

  • 2>&1 redirects stderr to stdout, capturing both regular output and errors
  • ; echo Exit code: $? displays the actual exit code after execution
  • This reveals the full Python traceback instead of opaque failure messages

Examples:

# Good: Full error capture
python3 process_data.py 2>&1 ; echo Exit code: $?

# Bad: Opaque error (no stderr capture, no exit code)
python3 process_data.py

2. Verify Working Directory Before File Operations

Before any file read/write operations in Python, verify the current working directory:

import os

# At script start, log the working directory
print(f"Working directory: {os.getcwd()}")

# For file operations, use absolute paths or log the resolved path
file_path = "output/result.csv"
abs_path = os.path.abspath(file_path)
print(f"Writing to: {abs_path}")

Why this works:

  • Many failures occur because scripts run from unexpected directories
  • Logging the working directory immediately surfaces path-related issues
  • Absolute paths prevent ambiguity in file operations

Full example script structure:

#!/usr/bin/env python3
import os
import sys

def main():
    # Debug: verify working directory
    print(f"Working directory: {os.getcwd()}", file=sys.stderr)
    
    # Debug: list directory contents if dealing with files
    print(f"Directory contents: {os.listdir('.')}", file=sys.stderr)
    
    # Your actual logic here
    # ...

if __name__ == "__main__":
    main()

When to Apply This Pattern

  • Python script fails with an opaque error message
  • File operations (read/write) fail unexpectedly
  • Script works locally but fails in automated execution
  • Debugging CI/CD pipeline failures
  • Investigating "file not found" or permission errors

Quick Checklist

  • Run script with 2>&1 ; echo Exit code: $? pattern
  • Add os.getcwd() logging at script start
  • Use os.path.abspath() for file paths
  • Log directory contents with os.listdir('.') if relevant
  • Check for missing dependencies (capture full traceback)

Common Failure Modes This Pattern Surfaces

Symptom Without Pattern With Pattern
File not found "Error: failed" Full traceback showing exact path attempted
Permission denied Script exits silently stderr shows permission error
Missing module Opaque exit ImportError with module name
Wrong directory Confusing path errors cwd logged, reveals directory mismatch
Perguntas frequentes

O que é um traceback?

Um traceback é a lista de passos que o Python executou antes de um erro, e mostra onde o problema aconteceu.

Por que registrar o caminho absoluto de um arquivo de saída?

Ele mostra exatamente onde o arquivo foi salvo, o que ajuda quando você não consegue encontrá-lo.

Posso usar isso sem editar meu script?

Sim. O comando de execução sozinho já mostra os erros, embora as linhas de diagnóstico ajudem mais.

Detalhes

Descrição original do autor

Debug Python script execution failures by capturing full output with exit codes and verifying working directory before file operations

repo: HKUDS/AgentPilot

Popularidade

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

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas