Skip to content
cccskills
FreePublished on GitHub

python-debug-pattern

Investigate Python script failures by capturing regular output, error details, and exit codes. Log the working directory and resolved file paths to expose missing files, permission problems, missing modules, or differences in automated execution.

OriginalShow the original description

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

See how to install

Good for

  • Investigating Python failures with unclear error messages
  • Checking paths when file reads or writes fail
  • Debugging scripts that fail only in automation
  • Identifying missing modules or permission errors

Files included (2)

  • SKILL.md3.1 KB
  • .skill_id34 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

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

SymptomWithout PatternWith Pattern
File not found"Error: failed"Full traceback showing exact path attempted
Permission deniedScript exits silentlystderr shows permission error
Missing moduleOpaque exitImportError with module name
Wrong directoryConfusing path errorscwd logged, reveals directory mismatch

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Prepare audio stems, the separate parts of a track, for mixing by matching their durations with silence, loops, or crossfades. Verify each generated and processed file before moving to the next production step.

  • Match audio parts with different durations
  • Extend drums and melodic parts using suitable methods
  • Check audio specifications before mixing
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Produce audio in separate stems, meaning individual instrument tracks, and verify each output as you go. Align track lengths with silence, loops, or crossfades, then apply effects, mix a master, and package the files.

  • Align instrument tracks to a reference audio file
  • Choose how to extend tracks that are too short
  • Verify audio properties after generation and effects
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Build serverless endpoints that relay external API requests for a dashboard while keeping API keys on the server. Includes Vercel examples for input checks, caching, cross-origin access, and consistent JSON responses.

  • Connect a dashboard to external APIs without exposing API keys
  • Create endpoints for stock quotes and news
  • Standardize API responses and error handling
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Produce a master track and separate audio parts through a structured Python workflow. Apply filters and reverb, export WAV files with consistent settings, package them in a ZIP archive, and check that the deliverables meet the requested specifications.

  • Export a master track with separate audio parts
  • Apply filters and reverb to audio
  • Check duration and format across deliverables
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

Keep document creation moving when web searches and page retrieval repeatedly fail. The skill preserves the original task, uses the model’s existing knowledge, and clearly identifies information that could not be checked against external sources.

  • Continue drafting after repeated web retrieval failures
  • Preserve task requirements during network errors
  • Mark information that could not be externally verified
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

When Python execution repeatedly fails in execute_code_sandbox, use a file-based alternative: save the script, run it through the shell, and capture results or errors. The guidance covers paths, imports, timeouts, structured output, and optional cleanup.

  • Retry Python work through the shell after repeated sandbox failures
  • Run longer tasks with an adjusted timeout
  • Execute Python work that needs multiple files or system utilities
HKUDS/OpenSpace7.8KUpdated Aug 13, 2026

See all skills by HKUDS

Report a problem with this skill