olivenet-iot avatar

error-handling

Common errors and fixes. Use when debugging or troubleshooting.

by olivenet-iot|Open Source

Error Handling

Common Errors

ErrorCauseFix
Telegram Parse ErrorMarkdown charsescape_markdown() veya parse_mode=None
Instagram Rate LimitToo many calls0.3s delay ekle
Video TimeoutSora/Kling slowgenerate_video_smart() kullan
Container FINISHED timeoutIG processingmax_attempts=30, sleep=10s
None.upper()Missing null check(value or "").upper()
JSON decode errorInvalid response_clean_json_response()

Retry Pattern

from app.agents.base_agent import retry_with_backoff

@retry_with_backoff(max_retries=3, base_delay=2.0)
async def my_function():
    # Delays: 2s, 4s, 8s (exponential)
    pass

Telegram Markdown Escape

def escape_markdown(text: str) -> str:
    chars = ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!']
    for char in chars:
        text = text.replace(char, f'\\{char}')
    return text

Instagram Container Polling

max_attempts = 30
for attempt in range(max_attempts):
    status = await check_container_status(container_id)
    if status["status_code"] == "FINISHED":
        break
    await asyncio.sleep(10)
else:
    raise TimeoutError("Container processing timeout")

Video Generation Fallback

# Kling fail → Sora fallback
result = await generate_video_smart(prompt, topic)
if not result["success"] and result.get("fallback"):
    result = await generate_video_sora(prompt)

JSON Cleanup

def clean_json(text: str) -> str:
    # Remove markdown code blocks
    if "```json" in text:
        text = text.split("```json")[1].split("```")[0]
    # Fix control characters
    text = text.replace('\n', '\\n').replace('\t', '\\t')
    return text.strip()

Debug Commands

# Check logs
tail -f /opt/olivenet-social-bot/logs/app.log

# Test database
sqlite3 data/content.db ".schema posts"

# Check bot status
systemctl status olivenet-social

# Restart bot
sudo systemctl restart olivenet-social

Deep Links

  • TROUBLESHOOTING.md - Full troubleshooting guide
  • app/agents/base_agent.py - Retry decorator
  • app/telegram_pipeline.py - escape_markdown()
error-handling - AI Agent Skill for Claude Code & Cursor | Agent Skills