Skip to content

Commit d2a5ba5

Browse files
committed
Migrated all exceptions to string interpolation
1 parent d6221ac commit d2a5ba5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/FSharp.Data.GraphQL.Client/Serialization.fs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Serialization =
2323
let private downcastNone<'T> t =
2424
match t with
2525
| Option t -> downcast (makeOption t null)
26-
| _ -> failwithf "Error parsing JSON value: %O is not an option value." t
26+
| _ -> failwith $"Error parsing JSON value: %O{t} is not an option value."
2727

2828
let private downcastType (t : Type) x =
2929
match t with
@@ -44,30 +44,30 @@ module Serialization =
4444
| t when isUriType t ->
4545
match Uri.TryCreate(s, UriKind.RelativeOrAbsolute) with
4646
| (true, uri) -> downcastType t uri
47-
| _ -> failwithf "Error parsing JSON value: %O is an URI type, but parsing of value \"%s\" failed." t s
47+
| _ -> failwith $"Error parsing JSON value: %O{t} is an URI type, but parsing of value \"%s{s}\" failed."
4848
| t when isDateTimeType t ->
4949
match DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None) with
5050
| (true, d) -> downcastType t d
51-
| _ -> failwithf "Error parsing JSON value: %O is a date type, but parsing of value \"%s\" failed." t s
51+
| _ -> failwith $"Error parsing JSON value: %O{t} is a date type, but parsing of value \"%s{s}\" failed."
5252
| t when isDateTimeOffsetType t ->
5353
match DateTimeOffset.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None) with
5454
| (true, d) -> downcastType t d
55-
| _ -> failwithf "Error parsing JSON value: %O is a date time offset type, but parsing of value \"%s\" failed." t s
55+
| _ -> failwith $"Error parsing JSON value: %O{t} is a date time offset type, but parsing of value \"%s{s}\" failed."
5656
| t when isGuidType t ->
5757
match Guid.TryParse(s) with
5858
| (true, g) -> downcastType t g
59-
| _ -> failwithf "Error parsing JSON value: %O is a Guid type, but parsing of value \"%s\" failed." t s
59+
| _ -> failwith $"Error parsing JSON value: %O{t} is a Guid type, but parsing of value \"%s{s}\" failed."
6060
| t when isEnumType t ->
6161
match t with
6262
| (Option et | et) ->
6363
try Enum.Parse(et, s) |> downcastType t
64-
with _ -> failwithf "Error parsing JSON value: %O is a Enum type, but parsing of value \"%s\" failed." t s
65-
| _ -> failwithf "Error parsing JSON value: %O is not a string type." t
64+
with _ -> failwith $"Error parsing JSON value: %O{t} is a Enum type, but parsing of value \"%s{s}\" failed."
65+
| _ -> failwith $"Error parsing JSON value: %O{t} is not a string type."
6666

6767
let private downcastBoolean (t : Type) b =
6868
match t with
6969
| t when isBooleanType t -> downcastType t b
70-
| _ -> failwithf "Error parsing JSON value: %O is not a boolean type." t
70+
| _ -> failwith $"Error parsing JSON value: %O{t} is not a boolean type."
7171

7272
let rec private getArrayValue (t : Type) (converter : Type -> JsonValue -> obj) (items : JsonValue []) =
7373
let castArray itemType (items : obj []) : obj =
@@ -93,15 +93,15 @@ module Serialization =
9393
| Option t -> getArrayValue t converter items |> makeOption t
9494
| Array itype | Seq itype -> items |> Array.map (converter itype) |> castArray itype
9595
| List itype -> items |> Array.map (converter itype) |> Array.toList |> castList itype
96-
| _ -> failwithf "Error parsing JSON value: %O is not an array type." t)
96+
| _ -> failwith $"Error parsing JSON value: %O{t} is not an array type.")
9797

9898
let private downcastNumber (t : Type) n =
9999
match t with
100100
| t when isNumericType t -> downcastType t n
101-
| _ -> failwithf "Error parsing JSON value: %O is not a numeric type." t
101+
| _ -> failwith $"Error parsing JSON value: %O{t} is not a numeric type."
102102

103103
let rec private convert t parsed : obj =
104-
Tracer.runAndMeasureExecutionTime (sprintf "Converted JsonValue to %O type." t) (fun _ ->
104+
Tracer.runAndMeasureExecutionTime $"Converted JsonValue to %O{t} type." (fun _ ->
105105
match parsed with
106106
| JsonValue.Null -> downcastNone t
107107
| JsonValue.String s -> downcastString t s
@@ -133,7 +133,7 @@ module Serialization =
133133

134134
let deserializeRecord<'T> (json : string) : 'T =
135135
let t = typeof<'T>
136-
Tracer.runAndMeasureExecutionTime (sprintf "Deserialized JSON string to record type %s." (t.ToString())) (fun _ ->
136+
Tracer.runAndMeasureExecutionTime $"Deserialized JSON string to record type %O{t}." (fun _ ->
137137
downcast (JsonValue.Parse(json) |> convert t))
138138

139139
let deserializeMap values =
@@ -159,7 +159,7 @@ module Serialization =
159159
then JsonValue.Null
160160
else
161161
let t = x.GetType()
162-
Tracer.runAndMeasureExecutionTime (sprintf "Converted object type %s to JsonValue" (t.ToString())) (fun _ ->
162+
Tracer.runAndMeasureExecutionTime $"Converted object type %O{t} to JsonValue" (fun _ ->
163163
match x with
164164
| null -> JsonValue.Null
165165
| OptionValue None -> JsonValue.Null
@@ -190,7 +190,7 @@ module Serialization =
190190
JsonValue.Record items)
191191

192192
let serializeRecord (x : obj) =
193-
Tracer.runAndMeasureExecutionTime (sprintf "Serialized object type %s to a JSON string" (x.GetType().ToString())) (fun _ ->
193+
Tracer.runAndMeasureExecutionTime $"Serialized object type %O{x.GetType()} to a JSON string" (fun _ ->
194194
(toJsonValue x).ToString())
195195

196196
let deserializeSchema (json : string) =

0 commit comments

Comments
 (0)