Skip to content

Add error tracking metrics to API main loop exception handlers #2935

@mgazza

Description

@mgazza

Summary

The main loop exception handlers in GECloud, GECloudData, Fox, and Octopus API clients silently swallow exceptions - they log them but don't track them for monitoring purposes. This makes it difficult to detect when API clients are experiencing repeated errors.

Problem

When an exception occurs in any of these main loops:

  • GECloud (apps/predbat/gecloud.py:875)
  • GECloudData (apps/predbat/gecloud.py:1455)
  • Fox API (apps/predbat/fox.py:142)
  • Octopus API (apps/predbat/octopus.py:440)

The error is logged but:

  1. failures_total counter is not incremented (inconsistent with API request failures)
  2. had_errors flag is not set (so monitoring systems can't detect issues)

Impact

Proposed Solution

Add error tracking to each main loop exception handler:

except Exception as e:
    self.log("Error: ... {}".format(e))
    self.failures_total += 1
    if hasattr(self.base, 'had_errors'):
        self.base.had_errors = True

This ensures:

  1. API failure metrics are incremented (consistent with other API failure tracking)
  2. General error flag is set for monitoring systems that check had_errors
  3. Uses hasattr() check for backwards compatibility

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions