Skip to content

Commit

Permalink
Tidy exns
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Aug 3, 2023
1 parent ae57138 commit 0a311d1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/Propulsion.CosmosStore/CosmosStorePruner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ type CosmosStorePrunerStats(log, statsInterval, stateInterval) =

override x.Classify e =
match e with
| Equinox_CosmosStore_Exceptions.RateLimited -> OutcomeKind.RateLimited
| Equinox_CosmosStore_Exceptions.RequestTimeout -> OutcomeKind.Timeout
| e -> base.Classify e
| Equinox.CosmosStore.Exceptions.RateLimited -> OutcomeKind.RateLimited
| Equinox.CosmosStore.Exceptions.RequestTimeout -> OutcomeKind.Timeout
| e -> base.Classify e
override _.HandleExn(log, exn) = log.Warning(exn, "Unhandled")

/// DANGER: <c>CosmosPruner</c> DELETES events - use with care
Expand Down
35 changes: 18 additions & 17 deletions src/Propulsion.CosmosStore/CosmosStoreSink.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ module private Impl =

let private toNativeEventBody (xs : Propulsion.Sinks.EventBody) : byte[] = xs.ToArray()
let defaultToNative_ = FsCodec.Core.TimelineEvent.Map toNativeEventBody
module internal Equinox =
module CosmosStore =
module Exceptions =
open Microsoft.Azure.Cosmos
let [<return: Struct>] (|CosmosStatus|_|) (x: exn) = match x with :? CosmosException as ce -> ValueSome ce.StatusCode | _ -> ValueNone
let (|RateLimited|RequestTimeout|CosmosStatusCode|Other|) = function
| CosmosStatus System.Net.HttpStatusCode.TooManyRequests -> RateLimited
| CosmosStatus System.Net.HttpStatusCode.RequestTimeout -> RequestTimeout
| CosmosStatus s -> CosmosStatusCode s
| _ -> Other

#else
module StreamSpan =

Expand All @@ -28,16 +39,6 @@ module private Impl =
let defaultToNative_ = FsCodec.Core.TimelineEvent.Map toNativeEventBody
#endif

module Equinox_CosmosStore_Exceptions =
open Microsoft.Azure.Cosmos
let [<return: Struct>] (|CosmosStatus|_|) (x: exn) = match x with :? CosmosException as ce -> ValueSome ce.StatusCode | _ -> ValueNone
let (|RateLimited|RequestTimeout|ServiceUnavailable|CosmosStatusCode|Other|) = function
| CosmosStatus System.Net.HttpStatusCode.TooManyRequests -> RateLimited
| CosmosStatus System.Net.HttpStatusCode.RequestTimeout -> RequestTimeout
| CosmosStatus System.Net.HttpStatusCode.ServiceUnavailable -> ServiceUnavailable
| CosmosStatus s -> CosmosStatusCode s
| _ -> Other

module Internal =

[<AutoOpen>]
Expand Down Expand Up @@ -86,14 +87,14 @@ module Internal =
m.Contains "SyntaxError: JSON.parse Error: Unexpected input at position"
|| m.Contains "SyntaxError: JSON.parse Error: Invalid character at position"
let classify = function
| Equinox_CosmosStore_Exceptions.RateLimited -> ResultKind.RateLimited
| Equinox_CosmosStore_Exceptions.RequestTimeout -> ResultKind.TimedOut
| Equinox_CosmosStore_Exceptions.CosmosStatusCode System.Net.HttpStatusCode.RequestEntityTooLarge -> ResultKind.TooLarge
| e when containsMalformedMessage e -> ResultKind.Malformed
| _ -> ResultKind.Other
| Equinox.CosmosStore.Exceptions.RateLimited -> ResultKind.RateLimited
| Equinox.CosmosStore.Exceptions.RequestTimeout -> ResultKind.TimedOut
| Equinox.CosmosStore.Exceptions.CosmosStatusCode System.Net.HttpStatusCode.RequestEntityTooLarge -> ResultKind.TooLarge
| e when containsMalformedMessage e -> ResultKind.Malformed
| _ -> ResultKind.Other
let isMalformed = function
| ResultKind.RateLimited | ResultKind.TimedOut | ResultKind.Other -> false
| ResultKind.TooLarge | ResultKind.Malformed -> true
| ResultKind.TooLarge | ResultKind.Malformed -> true

type Dispatcher =

Expand Down Expand Up @@ -169,7 +170,7 @@ type CosmosStoreSinkStats(log : ILogger, statsInterval, stateInterval) =
badCats.Clear(); tooLarge <- 0; malformed <- 0; resultExnOther <- 0; tlStreams.Clear(); mfStreams.Clear(); oStreams.Clear()
Equinox.CosmosStore.Core.Log.InternalMetrics.dump log

default _.HandleExn(_, _) : unit = ()
override _.HandleExn(log, exn) = log.Warning(exn, "Unhandled")

type CosmosStoreSink =

Expand Down
2 changes: 1 addition & 1 deletion src/Propulsion.DynamoStore.Notifier/Handler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let private publishBatch (client : IAmazonSimpleNotificationService) (log : Seri
if res.HttpStatusCode <> HttpStatusCode.OK || res.Failed.Count <> 0 then
let fails = [| for x in res.Failed -> struct (x.Code, x.SenderFault, x.Message) |]
log.Warning("PublishBatchAsync {res}. Fails: {fails}", res.HttpStatusCode, fails)
failwithf "PublishBatchAsync result %A %A" res.HttpStatusCode fails }
failwithf $"PublishBatchAsync result {res.HttpStatusCode} %A{fails}" }

type SnsClient(topicArn) =

Expand Down
2 changes: 1 addition & 1 deletion src/Propulsion.EventStore/EventStoreSink.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type EventStoreSinkStats(log : ILogger, statsInterval, stateInterval) =
badCats.Clear(); resultExnOther <- 0; oStreams.Clear()
Log.InternalMetrics.dump log

default _.HandleExn(_, _) : unit = ()
override _.HandleExn(log, exn) = log.Warning(exn, "Unhandled")

type EventStoreSink =

Expand Down

0 comments on commit 0a311d1

Please sign in to comment.