Skip to content

Conversation

@mgazza
Copy link
Collaborator

@mgazza mgazza commented Nov 17, 2025

Summary

Fixes #2935

  • Adds failure counter increment to API main loop exception handlers
  • Sets had_errors flag for monitoring systems
  • Applies to GECloud, GECloudData, Fox API, and Octopus API

Problem

When exceptions occur in API main loops, they are logged but not tracked for monitoring. This makes it impossible to alert on repeated errors or track API health metrics accurately.

For example, the recent EVC device bug (#2931) was causing errors every 60 seconds, but monitoring systems couldn't detect it because:

  • failures_total wasn't incremented
  • had_errors wasn't set

Changes

Added to each main loop exception handler:

self.failures_total += 1
if hasattr(self.base, "had_errors"):
    self.base.had_errors = True

Files modified:

  • apps/predbat/gecloud.py - GECloud and GECloudData main loops
  • apps/predbat/fox.py - Fox API main loop
  • apps/predbat/octopus.py - Octopus API main loop

Test plan

  • Pre-commit hooks pass (ruff, black, cspell)
  • Uses hasattr() for backwards compatibility
  • Consistent with existing API failure tracking pattern
  • Verify failures_total increments on exception
  • Verify had_errors flag is set when present on base

🤖 Generated with Claude Code

Fixes springfall2008#2935

Adds failure counter increment and had_errors flag setting to main loop
exception handlers in:
- GECloud
- GECloudData
- Fox API
- Octopus API

This ensures that repeated exceptions in API main loops are tracked for
monitoring and alerting purposes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@springfall2008
Copy link
Owner

Setting had_errors may confuse things as the components run async to the main loop, it could even be set when the loop isn't computing and so it will be lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add error tracking metrics to API main loop exception handlers

2 participants