fix: no-op on PostHog API failures#218
Conversation
posthog-dotnet Compliance ReportDate: 2026-06-01 06:43:17 UTC
|
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ❌ | 42ms |
| Request Payload.Flags Request Uses V2 Query Param | ❌ | 20ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ❌ | 5ms |
| Request Payload.Flags Request Omits Authorization Header | ❌ | 5ms |
| Request Payload.Token In Flags Body Matches Init | ❌ | 4ms |
| Request Payload.Groups Round Trip | ❌ | 5ms |
| Request Payload.Groups Default To Empty Object | ❌ | 5ms |
| Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It | ❌ | 4ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ❌ | 5ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 5ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ❌ | 5ms |
| Request Lifecycle.No Flags Request On Init Alone | ✅ | 3ms |
| Request Lifecycle.No Flags Request On Normal Capture | ✅ | 179ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ❌ | 7ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ❌ | 4ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ❌ | 5ms |
Failures
request_payload.request_with_person_properties_device_id
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_uses_v2_query_param
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_hits_flags_path_not_decide
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_omits_authorization_header
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.token_in_flags_body_matches_init
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.groups_round_trip
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.groups_default_to_empty_object
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.disable_geoip_false_propagates_as_geoip_disable_false
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.disable_geoip_omitted_defaults_to_false
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flag_keys_to_evaluate_contains_only_requested_key
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_lifecycle.two_flag_calls_produce_two_remote_requests
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_lifecycle.mock_response_value_is_returned_to_caller
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
side_effect_events.get_feature_flag_captures_feature_flag_called_event
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
| // Lock the source file exclusively so File.ReadAllLines(sourcePath) will throw IOException | ||
| // and as result frames will not contain source code context. Use a temp file so parallel | ||
| // target-framework test runs do not contend over this test source file. |
There was a problem hiding this comment.
this was flaky already so not really related to this PR but it was failing quite often
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/PostHog/PostHogClient.cs:1192-1195
The `FlushAsync` catch filter omits the `ArgumentException` and `NullReferenceException` exclusions that every other catch block introduced in this PR carries. This means a programming error surfacing from `_asyncBatchHandler.FlushAsync()` (e.g., a `NullReferenceException` deep in the batch handler) would be silently logged instead of propagating, hiding real bugs. All sibling catch blocks explicitly let these exception types through (`when (e is not ArgumentException and not NullReferenceException and not OperationCanceledException)`); this one should match.
```suggestion
catch (Exception e) when (e is not ArgumentException and not NullReferenceException and not OperationCanceledException)
{
_logger.LogErrorApiCallFailed(e, nameof(FlushAsync));
}
```
Reviews (1): Last reviewed commit: "test: isolate exception source file lock" | Re-trigger Greptile |
💡 Motivation and Context
The .NET SDK should not crash the host application when PostHog is non-operational, including invalid project tokens or API/auth failures. Some public methods awaited API calls directly and could surface exceptions to the caller.
Changes:
ApiResult(0)from direct ingestion APIs when PostHog API calls fail.FlushAsync,LoadFeatureFlagsAsync, and local feature flag loading paths while returning safe defaults.💚 How did you test it?
dotnet test tests/UnitTests/UnitTests.csproj --no-restore --filter "FullyQualifiedName~TheApiFailureNoOpBehavior|FullyQualifiedName~TheDisabledClient|FullyQualifiedName~TheLoadFeatureFlagsAsyncMethod|FullyQualifiedName~ETagSupport"dotnet test tests/UnitTests/UnitTests.csproj --no-restore --filter "FullyQualifiedName~TheQuotaLimitBehavior|FullyQualifiedName~FeatureFlagsTests"📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file