Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error #2

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions native/runtime/ppx_deriving_router_primitives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ let float_of_url_query k xs =
| None -> Error "missing value"
| Some x -> (
match float_of_string_opt x with
| None -> Error "not a float value"
| None ->
Error
(Printf.sprintf
"expected a float value, instead received: %s" x)
| Some x -> Ok x))

let int_to_url_query k x = [ k, string_of_int x ]
Expand All @@ -38,7 +41,10 @@ let int_of_url_query k xs =
| None -> Error "missing value"
| Some x -> (
match int_of_string_opt x with
| None -> Error "not an integer value"
| None ->
Error
(Printf.sprintf
"expected an integer value, instead received: %s" x)
| Some x -> Ok x))

let bool_to_url_query k x = if x then [ k, "true" ] else []
Expand All @@ -48,7 +54,12 @@ let bool_of_url_query k xs =
| None -> Ok false
| Some "true" -> Ok true
| Some "false" -> Ok false
| _ -> Error "not a boolean value (true, false)")
| Some v ->
Error
(Printf.sprintf
"expected a boolean value (true, false), instead received: \
%s"
v))

let option_to_url_query f k x =
match x with None -> [] | Some v -> f k v
Expand Down