with one click
pdf-gen-fallback-dee20c
Fallback workflow for document generation when code sandbox returns opaque errors
Menu
Fallback workflow for document generation when code sandbox returns opaque errors
| name | pdf-gen-fallback-dee20c |
| description | Fallback workflow for document generation when code sandbox returns opaque errors |
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.
execute_code_sandbox fails with unclear error messages during document generationBefore 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
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')
"
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
After generation, confirm the file was created:
run_shell: ls -la output.pdf
run_shell: file output.pdf
If the first approach fails, try alternatives in this order:
reportlab - Full-featured PDF generationfpdf - Simpler PDF librarywkhtmltopdf - HTML to PDF conversion# 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'
| Issue | Solution |
|---|---|
| Module not found | pip install <module> --quiet |
| Permission denied | Check output directory permissions |
| Font errors | Use default fonts or install font packages |
| Encoding issues | Specify encoding explicitly in string operations |
python -c.py file insteadDelegate tasks to OpenSpace — a full-stack autonomous worker for coding, DevOps, web research, and desktop automation, backed by an extensive MCP tool and skill library. Skills auto-improve through use, reducing token consumption over time. A cloud community lets agents share and collectively evolve reusable skills.
Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification
Audio production with diagnostic analysis, timecode parsing from documents, and verified export workflow
Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies
Step-by-step audio production with per-stem verification, timing alignment, and incremental quality gates
End-to-end audio production workflow with stems, effects, archiving, and verification