跳到正文
cccskills
免费在 GitHub 公开

pdf-gen-fallback-dee20c

Recover document and PDF generation tasks when sandbox errors provide little detail. Checks Python libraries, runs generation through the shell, captures errors, and verifies output files, with alternative PDF tools and text output as fallback options.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Fallback workflow for document generation when code sandbox returns opaque errors

查看安装方法

适用场景

  • Recovering PDF generation after unclear sandbox errors
  • Checking required PDF libraries before generation
  • Capturing detailed document generation errors
  • Trying alternative tools when PDF creation fails

包含的文件(2)

  • SKILL.md3.6 KB
  • .skill_id37 B

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

PDF Generation Fallback Workflow

Purpose

When execute_code_sandbox returns opaque or unhelpful errors during document/PDF generation, use run_shell with direct python -c execution as a reliable alternative. This pattern includes library availability checks and explicit error handling.

When to Use

  • execute_code_sandbox fails with unclear error messages during document generation
  • PDF, report, or document creation tasks are failing unexpectedly
  • You need more control over the Python execution environment

Step-by-Step Instructions

1. Check Library Availability

Before attempting generation, verify required libraries are installed:

run_shell: python -c "import reportlab; print('reportlab OK')"
run_shell: python -c "import fpdf; print('fpdf OK')"
run_shell: python -c "import PyPDF2; print('PyPDF2 OK')"

If a library is missing, install it:

run_shell: pip install reportlab --quiet

2. Execute Generation via run_shell

Instead of execute_code_sandbox, use run_shell with python -c:

run_shell: python -c "
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas('output.pdf', pagesize=letter)
c.drawString(100, 750, 'Document Content')
c.save()
print('PDF generated successfully')
"

3. Handle Errors Explicitly

Wrap generation code with try/except and capture stderr:

run_shell: python -c "
import sys
try:
    # Your generation code here
    from reportlab.pdfgen import canvas
    c = canvas.Canvas('output.pdf')
    c.drawString(100, 750, 'Content')
    c.save()
    print('SUCCESS: PDF created')
    sys.exit(0)
except Exception as e:
    print(f'ERROR: {type(e).__name__}: {e}', file=sys.stderr)
    sys.exit(1)
" 2>&1

4. Verify Output File

After generation, confirm the file was created:

run_shell: ls -la output.pdf
run_shell: file output.pdf

5. Fallback Hierarchy

If the first approach fails, try alternatives in this order:

  1. reportlab - Full-featured PDF generation
  2. fpdf - Simpler PDF library
  3. wkhtmltopdf - HTML to PDF conversion
  4. Direct text/Markdown output as last resort

Example: Complete Workflow

# Step 1: Check library
run_shell: python -c "import reportlab; print('OK')"

# Step 2: Generate with error handling
run_shell: python -c "
import sys
try:
    from reportlab.lib.pagesizes import letter
    from reportlab.pdfgen import canvas
    c = canvas.Canvas('report.pdf', pagesize=letter)
    c.setTitle('Surveillance Report')
    c.drawString(100, 750, 'Revised Surveillance Report')
    c.drawString(100, 730, 'Summary: Key findings documented')
    c.save()
    print('SUCCESS')
except Exception as e:
    print(f'FAILED: {e}', file=sys.stderr)
    sys.exit(1)
"

# Step 3: Verify
run_shell: test -f report.pdf && echo 'File exists' || echo 'File missing'

Troubleshooting

IssueSolution
Module not foundpip install <module> --quiet
Permission deniedCheck output directory permissions
Font errorsUse default fonts or install font packages
Encoding issuesSpecify encoding explicitly in string operations

Best Practices

  • Always capture both stdout and stderr for debugging
  • Exit with proper status codes (0 for success, 1 for failure)
  • Keep generation code concise when using python -c
  • For complex generation, write a temporary .py file instead
  • Test library availability before attempting generation

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

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/OpenSpace77592026年8月13日 更新

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/OpenSpace77592026年8月13日 更新

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/OpenSpace77592026年8月13日 更新

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/OpenSpace77592026年8月13日 更新

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/OpenSpace77592026年8月13日 更新

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/OpenSpace77592026年8月13日 更新

查看 HKUDS 的全部技能

报告此技能的问题