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 b797b7a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 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 @@ -209,8 +209,9 @@ 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
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 b797b7a

Please sign in to comment.