From bc0baccfa36951ccd2c8b6171cba61a705e12158 Mon Sep 17 00:00:00 2001 From: Giacomo Cavalieri Date: Mon, 28 Apr 2025 20:09:40 +0200 Subject: [PATCH] :recycle: Reword decode failure messages --- ...t_needs_more_than_a_single_helper_function.accepted | 2 +- ...ecursive_common_table_query_with_semi_join.accepted | 2 +- ...ce_results_in_a_single_uuid_decoder_helper.accepted | 2 +- birdie_snapshots/uuid_decoding.accepted | 2 +- src/squirrel/internal/database/postgres.gleam | 10 +++++----- src/squirrel/internal/query.gleam | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/birdie_snapshots/query_that_needs_more_than_a_single_helper_function.accepted b/birdie_snapshots/query_that_needs_more_than_a_single_helper_function.accepted index 259ba0d..d8badec 100644 --- a/birdie_snapshots/query_that_needs_more_than_a_single_helper_function.accepted +++ b/birdie_snapshots/query_that_needs_more_than_a_single_helper_function.accepted @@ -45,6 +45,6 @@ fn uuid_decoder() { use bit_array <- decode.then(decode.bit_array) case uuid.from_bit_array(bit_array) { Ok(uuid) -> decode.success(uuid) - Error(_) -> decode.failure(uuid.v7(), "uuid") + Error(_) -> decode.failure(uuid.v7(), "Uuid") } } diff --git a/birdie_snapshots/recursive_common_table_query_with_semi_join.accepted b/birdie_snapshots/recursive_common_table_query_with_semi_join.accepted index caee80c..9a6fc8f 100644 --- a/birdie_snapshots/recursive_common_table_query_with_semi_join.accepted +++ b/birdie_snapshots/recursive_common_table_query_with_semi_join.accepted @@ -61,6 +61,6 @@ fn uuid_decoder() { use bit_array <- decode.then(decode.bit_array) case uuid.from_bit_array(bit_array) { Ok(uuid) -> decode.success(uuid) - Error(_) -> decode.failure(uuid.v7(), "uuid") + Error(_) -> decode.failure(uuid.v7(), "Uuid") } } diff --git a/birdie_snapshots/using_uuids_more_than_once_results_in_a_single_uuid_decoder_helper.accepted b/birdie_snapshots/using_uuids_more_than_once_results_in_a_single_uuid_decoder_helper.accepted index b1b6516..4068f06 100644 --- a/birdie_snapshots/using_uuids_more_than_once_results_in_a_single_uuid_decoder_helper.accepted +++ b/birdie_snapshots/using_uuids_more_than_once_results_in_a_single_uuid_decoder_helper.accepted @@ -72,6 +72,6 @@ fn uuid_decoder() { use bit_array <- decode.then(decode.bit_array) case uuid.from_bit_array(bit_array) { Ok(uuid) -> decode.success(uuid) - Error(_) -> decode.failure(uuid.v7(), "uuid") + Error(_) -> decode.failure(uuid.v7(), "Uuid") } } diff --git a/birdie_snapshots/uuid_decoding.accepted b/birdie_snapshots/uuid_decoding.accepted index 7f525bc..4c08b64 100644 --- a/birdie_snapshots/uuid_decoding.accepted +++ b/birdie_snapshots/uuid_decoding.accepted @@ -44,6 +44,6 @@ fn uuid_decoder() { use bit_array <- decode.then(decode.bit_array) case uuid.from_bit_array(bit_array) { Ok(uuid) -> decode.success(uuid) - Error(_) -> decode.failure(uuid.v7(), "uuid") + Error(_) -> decode.failure(uuid.v7(), "Uuid") } } diff --git a/src/squirrel/internal/database/postgres.gleam b/src/squirrel/internal/database/postgres.gleam index 8b03f93..4cf699c 100644 --- a/src/squirrel/internal/database/postgres.gleam +++ b/src/squirrel/internal/database/postgres.gleam @@ -17,7 +17,7 @@ import eval import gleam/bit_array import gleam/bool import gleam/dict.{type Dict} -import gleam/dynamic/decode +import gleam/dynamic/decode.{type Decoder} import gleam/int import gleam/json import gleam/list @@ -1356,18 +1356,18 @@ fn adjust_parse_error_for_explain(error: Error) -> Error { // --- DECODERS ---------------------------------------------------------------- -fn json_plans_decoder() { +fn json_plans_decoder() -> Decoder(List(Plan)) { decode.list(decode.at(["Plan"], plan_decoder())) } -fn plan_decoder() { +fn plan_decoder() -> Decoder(Plan) { use join_type <- decode.optional_field("Join Type", None, join_type_decoder()) use output <- decode.optional_field("Output", [], decode.list(decode.string)) use plans <- decode.optional_field("Plans", [], decode.list(plan_decoder())) decode.success(Plan(join_type:, output:, plans:)) } -fn join_type_decoder() { +fn join_type_decoder() -> Decoder(Option(JoinType)) { use data <- decode.then(decode.string) case data { "Full" -> decode.success(Some(FullJoin)) @@ -1375,7 +1375,7 @@ fn join_type_decoder() { "Right" -> decode.success(Some(RightJoin)) "Inner" -> decode.success(Some(InnerJoin)) "Semi" -> decode.success(Some(SemiJoin)) - _ -> decode.failure(None, "a join type") + _ -> decode.failure(None, "JoinType") } } diff --git a/src/squirrel/internal/query.gleam b/src/squirrel/internal/query.gleam index df40b54..3c53c8f 100644 --- a/src/squirrel/internal/query.gleam +++ b/src/squirrel/internal/query.gleam @@ -709,7 +709,7 @@ fn uuid_decoder() { use bit_array <- decode.then(decode.bit_array) case uuid.from_bit_array(bit_array) { Ok(uuid) -> decode.success(uuid) - Error(_) -> decode.failure(uuid.v7(), \"uuid\") + Error(_) -> decode.failure(uuid.v7(), \"Uuid\") } }" -- 2.51.2