GrowattError enum represents all possible errors that can occur when using the Growatt API client. It uses the thiserror crate for ergonomic error handling.
Error Types
This enum is defined in
src/lib.rs:14-30 and implements the Error and Debug traits via the thiserror crate.Result Type
The library provides a convenientResult type alias:
Result<T> where T is the expected success type.
Error Variants
Wraps HTTP request errors from the underlying
reqwest library. This includes network errors, timeouts, connection failures, and HTTP status errors.Common causes:- Network connectivity issues
- DNS resolution failures
- Request timeouts
- Server unavailable (5xx errors)
- Client errors (4xx errors)
Wraps JSON parsing/serialization errors from
serde_json. Occurs when the API returns unexpected or malformed JSON.Common causes:- API response format changed
- Malformed JSON from server
- Missing required fields in response
- Type mismatches in deserialization
Authentication failed. Contains a message describing the authentication failure.Common causes:
- Invalid username or password
- Account locked or disabled
- Session expired on server side
- Authentication token rejected
The API returned a valid HTTP response but the content was invalid or unexpected. Contains a message describing what was invalid.Common causes:
- Empty response when data was expected
- Missing expected fields in JSON structure
- Null values where data was expected
- Response indicates failure (e.g.,
result != 1)
Attempted to call an API method without being authenticated. No credentials are stored to attempt automatic login.Common causes:
- Calling API methods before
login() - Session expired and no credentials available for auto-renewal
- Explicit logout followed by API call
Error Handling Examples
Basic Match Pattern
Using the ? Operator
The? operator can be used to propagate errors up the call stack:
Handling Specific Errors
Logging Errors
Retry Logic
Error Conversion
The#[from] attribute on RequestError and JsonError enables automatic conversion:
Best Practices
All errors implement the standard
Error trait, so they can be used with error handling libraries like anyhow or eyre: