Skip to content

fix: clean up HTML error messages in CLI display#3069

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-e483085e
Mar 25, 2026
Merged

fix: clean up HTML error messages in CLI display#3069
teknium1 merged 1 commit intomainfrom
hermes/hermes-e483085e

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Fixes ugly HTML error message display in the CLI when API calls fail.

Problem

When API services (like OpenRouter) return HTML error pages instead of JSON errors (common with CloudFlare protection, rate limiting, etc.), the CLI was dumping raw HTML content to users:

┊ 💻 preparing terminal…⚠️  API call failed (attempt 1/3): InternalServerError   
🔌 Provider: openrouter  Model: anthropic/claude-opus-4.6   
🌐 Endpoint: https://openrouter.ai/api/v1   
📝 Error: <!DOCTYPE html><!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]--><!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]--><!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]--><!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->

Solution

  • Added _clean_error_message() utility method to AIAgent class
  • Detects HTML content and replaces with user-friendly message
  • Also handles multiline errors and truncates overly long messages
  • Applied to all user-facing error displays in the agent loop

After

┊ 💻 preparing terminal…⚠️  API call failed (attempt 1/3): InternalServerError   
🔌 Provider: openrouter  Model: anthropic/claude-opus-4.6   
🌐 Endpoint: https://openrouter.ai/api/v1   
📝 Error: Service temporarily unavailable (HTML error page returned)

Test plan

  • ✅ All existing tests pass (pytest tests/test_run_agent.py)
  • ✅ Function correctly detects and cleans HTML errors
  • ✅ Preserves meaningful text from regular errors
  • ✅ Handles edge cases (empty errors, multiline, very long)

Raw error details are still logged to gateway.log for debugging - only user-facing display is cleaned.

@teknium1 teknium1 merged commit bd6b138 into main Mar 25, 2026
4 checks passed
outsourc-e pushed a commit to outsourc-e/hermes-agent that referenced this pull request Mar 26, 2026
When API calls fail with HTML error pages (e.g., CloudFlare errors), the CLI
was dumping raw HTML content to users like:
  📝 Error: <!DOCTYPE html><!--[if lt IE 7]> <html class="no-js ie6...

This commit adds a _clean_error_message() utility method that:
- Detects HTML content and replaces with user-friendly message
- Collapses multiline errors to single line
- Truncates overly long errors (>150 chars)
- Preserves meaningful error text for regular errors

Applied to all user-facing error displays:
- API call failure messages (line 6314)
- Interrupt error responses (line 6324)
- Invalid response error messages (line 6000)

Before: 📝 Error: <!DOCTYPE html><!--[if lt IE 7]>...
After:  📝 Error: Service temporarily unavailable (HTML error page returned)
StreamOfRon pushed a commit to StreamOfRon/hermes-agent that referenced this pull request Mar 29, 2026
When API calls fail with HTML error pages (e.g., CloudFlare errors), the CLI
was dumping raw HTML content to users like:
  📝 Error: <!DOCTYPE html><!--[if lt IE 7]> <html class="no-js ie6...

This commit adds a _clean_error_message() utility method that:
- Detects HTML content and replaces with user-friendly message
- Collapses multiline errors to single line
- Truncates overly long errors (>150 chars)
- Preserves meaningful error text for regular errors

Applied to all user-facing error displays:
- API call failure messages (line 6314)
- Interrupt error responses (line 6324)
- Invalid response error messages (line 6000)

Before: 📝 Error: <!DOCTYPE html><!--[if lt IE 7]>...
After:  📝 Error: Service temporarily unavailable (HTML error page returned)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant