# PowerPoint Creation - Common Errors & Fixes

## CRITICAL: Build Incrementally

**DO NOT** write a single massive script that creates the entire presentation. If it fails on slide 15, you lose everything.

**Instead, build iteratively:**

```python
# Step 1: Create presentation with title slide, save it
from pptx import Presentation
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Q1 Report"
prs.save("/workspace/presentation.pptx")
```

```python
# Step 2: Load and add next slide
prs = Presentation("/workspace/presentation.pptx")
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "Executive Summary"
# ... add content ...
prs.save("/workspace/presentation.pptx")
```

```python
# Step 3: Load and add another slide
prs = Presentation("/workspace/presentation.pptx")
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "Financial Overview"
# ... add content ...
prs.save("/workspace/presentation.pptx")
```

**Benefits:**
- If slide 3 fails, slides 1-2 are already saved
- Easier to debug which slide caused the error
- Can verify each slide looks correct before continuing

---

## Error: RgbColor format issues

**Wrong:**
```python
from pptx.dml.color import RgbColor
color = RgbColor(26, 115, 232)  # Integers don't work
color = RgbColor("#1A73E8")     # Strings don't work
```

**Correct:**
```python
from pptx.dml.color import RgbColor
color = RgbColor(0x1A, 0x73, 0xE8)  # Must use hex literals

# Or convert from RGB integers:
r, g, b = 26, 115, 232
color = RgbColor(r, g, b)  # This works if values are 0-255 integers
```

**Also correct - use theme colors instead:**
```python
from pptx.enum.dml import MSO_THEME_COLOR
shape.fill.solid()
shape.fill.fore_color.theme_color = MSO_THEME_COLOR.ACCENT_1
```

---

## Error: OSError [Errno 22] Invalid argument on save

```
OSError: [Errno 22] Invalid argument
```

**Causes:**
1. Invalid file path (special characters, missing directory)
2. Writing to read-only location
3. Path doesn't exist

**Fix:**
```python
import os

# Always use /workspace/ and ensure directory exists
output_path = "/workspace/outputs/presentation.pptx"
os.makedirs(os.path.dirname(output_path), exist_ok=True)
prs.save(output_path)
```

**Never do:**
```python
prs.save("presentation.pptx")  # Relative path - may fail
prs.save("/tmp/presentation.pptx")  # /tmp may have issues
```

---

## Output Location

Always save to `/workspace/`:
```python
prs.save("/workspace/my_presentation.pptx")
```
