Skip to content

Commit

Permalink
Be safe on parsing errors only
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Oct 3, 2023
1 parent 4bf12a5 commit 61959f2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/FSharpPlus/Control/Converter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ type TryParse =
match DateTimeOffset.TryParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffK"; "yyyy-MM-ddTHH:mm:ssK"|], null, DateTimeStyles.AssumeUniversal) with
| true, x -> Some x
| _ ->
match DateTimeOffset.TryParse (x, CultureInfo.InvariantCulture, DateTimeStyles.None) with
| true, x -> Some x
| _ -> None
match DateTimeOffset.TryParse (x, CultureInfo.InvariantCulture, DateTimeStyles.None) with
| true, x -> Some x
| _ -> None
#endif

static member inline Invoke (value: string) =
Expand Down Expand Up @@ -208,9 +208,10 @@ type Parse with

type TryParse with

static member inline TryParse (_: 'R, _: Default4) : string -> 'R option = fun (value: string) ->
try Parse.InvokeOnInstance value |> Some
with _ -> None // todo, maybe match on invalidArg only
static member inline TryParse (_: 'R, _: Default4) : string -> 'R option = fun (value: string) ->
try Some (Parse.InvokeOnInstance value) with
| :? ArgumentNullException | :? FormatException -> None
| _ -> reraise ()

static member inline TryParse (_: 'R, _: Default3) : string -> 'R option = TryParse.InvokeOnConvention

Expand Down

0 comments on commit 61959f2

Please sign in to comment.