From 3f43d209c24772a4dc90f3933a9c25e1f90b78ab Mon Sep 17 00:00:00 2001 From: Patrick Tschorn Date: Fri, 1 Nov 2024 16:21:07 +0000 Subject: [PATCH 1/8] log errors on make_encoder; bump version --- lib/avrogen/schema/schema_registry.ex | 22 ++++++++++++++++++---- mix.exs | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/avrogen/schema/schema_registry.ex b/lib/avrogen/schema/schema_registry.ex index f415523..37defbf 100644 --- a/lib/avrogen/schema/schema_registry.ex +++ b/lib/avrogen/schema/schema_registry.ex @@ -5,6 +5,7 @@ defmodule Avrogen.Schema.SchemaRegistry do """ use GenServer + use Logger @ets_name "all" @@ -39,10 +40,23 @@ defmodule Avrogen.Schema.SchemaRegistry do end) |> Avrogen.Schema.topological_sort() |> Noether.Either.map(fn schemas -> - json = Jason.encode!(schemas) - encoder = make_encoder(json) - decoder = make_decoder(json) - :ets.insert(__MODULE__, {@ets_name, json, encoder, decoder}) + try do + json = Jason.encode!(schemas) + encoder = make_encoder(json) + decoder = make_decoder(json) + :ets.insert(__MODULE__, {@ets_name, json, encoder, decoder}) + rescue + e -> + formatted_error = Exception.format(:error, e, __STACKTRACE__) + + Logger.error("Error when attempting to make encoder/decoder.", + error: formatted_error, + schemas: schemas, + schemas_json: json + ) + + reraise(e) + end end) {:ok, table} diff --git a/mix.exs b/mix.exs index ee59a47..c350da1 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Avrogen.MixProject do use Mix.Project - @version "0.7.1" + @version "0.7.2" @source_url "https://github.com/primait/avrogen" def project do From cfa5685f61378e3b3a3699604ad955b3ffd0d65d Mon Sep 17 00:00:00 2001 From: Patrick Tschorn Date: Fri, 1 Nov 2024 16:28:23 +0000 Subject: [PATCH 2/8] fix --- lib/avrogen/schema/schema_registry.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/avrogen/schema/schema_registry.ex b/lib/avrogen/schema/schema_registry.ex index 37defbf..1477ad0 100644 --- a/lib/avrogen/schema/schema_registry.ex +++ b/lib/avrogen/schema/schema_registry.ex @@ -5,7 +5,7 @@ defmodule Avrogen.Schema.SchemaRegistry do """ use GenServer - use Logger + require Logger @ets_name "all" @@ -49,13 +49,13 @@ defmodule Avrogen.Schema.SchemaRegistry do e -> formatted_error = Exception.format(:error, e, __STACKTRACE__) - Logger.error("Error when attempting to make encoder/decoder.", + Logger.error("Error when attempting to make encoder/decoder: #{formatted_error}", error: formatted_error, schemas: schemas, - schemas_json: json + schemas_json: Jason.encode(schemas) ) - reraise(e) + reraise e, __STACKTRACE__ end end) From 07503d79d3b1c7d47102d768c10d7e9428f76811 Mon Sep 17 00:00:00 2001 From: Patrick Tschorn Date: Fri, 1 Nov 2024 16:31:27 +0000 Subject: [PATCH 3/8] credo --- lib/avrogen/schema/schema_registry.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/avrogen/schema/schema_registry.ex b/lib/avrogen/schema/schema_registry.ex index 1477ad0..7e062e8 100644 --- a/lib/avrogen/schema/schema_registry.ex +++ b/lib/avrogen/schema/schema_registry.ex @@ -49,11 +49,11 @@ defmodule Avrogen.Schema.SchemaRegistry do e -> formatted_error = Exception.format(:error, e, __STACKTRACE__) - Logger.error("Error when attempting to make encoder/decoder: #{formatted_error}", + Logger.error("Error when attempting to make encoder/decoder: #{formatted_error}", %{ error: formatted_error, schemas: schemas, schemas_json: Jason.encode(schemas) - ) + }) reraise e, __STACKTRACE__ end From 5bc28a01bd6742a444d6df9bb2e8083fad2bd198 Mon Sep 17 00:00:00 2001 From: Patrick Tschorn Date: Fri, 1 Nov 2024 16:34:58 +0000 Subject: [PATCH 4/8] put detail into error message so that it will show up in CI --- lib/avrogen/schema/schema_registry.ex | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/avrogen/schema/schema_registry.ex b/lib/avrogen/schema/schema_registry.ex index 7e062e8..472113b 100644 --- a/lib/avrogen/schema/schema_registry.ex +++ b/lib/avrogen/schema/schema_registry.ex @@ -48,12 +48,16 @@ defmodule Avrogen.Schema.SchemaRegistry do rescue e -> formatted_error = Exception.format(:error, e, __STACKTRACE__) - - Logger.error("Error when attempting to make encoder/decoder: #{formatted_error}", %{ - error: formatted_error, - schemas: schemas, - schemas_json: Jason.encode(schemas) - }) + json = Jason.encode(schemas) |> elem(1) + + Logger.error( + "Error when attempting to make encoder/decoder: #{formatted_error}; schemas: #{inspect(schemas)} schemas_json: #{json}", + %{ + error: formatted_error, + schemas: schemas, + schemas_json: json + } + ) reraise e, __STACKTRACE__ end From 8b3f08569a14086088d5aacadf2ef8db555711ae Mon Sep 17 00:00:00 2001 From: Patrick Tschorn Date: Mon, 4 Nov 2024 15:09:42 +0000 Subject: [PATCH 5/8] Oli's suggestions --- lib/avrogen/schema/schema_registry.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/avrogen/schema/schema_registry.ex b/lib/avrogen/schema/schema_registry.ex index 472113b..2c8bdb4 100644 --- a/lib/avrogen/schema/schema_registry.ex +++ b/lib/avrogen/schema/schema_registry.ex @@ -40,18 +40,18 @@ defmodule Avrogen.Schema.SchemaRegistry do end) |> Avrogen.Schema.topological_sort() |> Noether.Either.map(fn schemas -> + json = Jason.encode!(schemas) + try do - json = Jason.encode!(schemas) encoder = make_encoder(json) decoder = make_decoder(json) :ets.insert(__MODULE__, {@ets_name, json, encoder, decoder}) rescue e -> formatted_error = Exception.format(:error, e, __STACKTRACE__) - json = Jason.encode(schemas) |> elem(1) Logger.error( - "Error when attempting to make encoder/decoder: #{formatted_error}; schemas: #{inspect(schemas)} schemas_json: #{json}", + "Error when attempting to make encoder/decoder: #{formatted_error}; schemas: #{inspect(schemas, limit: :infinity, pretty: true, printable_limit: :infinity)} schemas_json: #{elem(json, 1)}", %{ error: formatted_error, schemas: schemas, From d3fa21db905e362a378670f4b8b0ccfb950c7519 Mon Sep 17 00:00:00 2001 From: Patrick Tschorn Date: Mon, 4 Nov 2024 15:20:40 +0000 Subject: [PATCH 6/8] ... --- lib/avrogen/schema/schema_registry.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/avrogen/schema/schema_registry.ex b/lib/avrogen/schema/schema_registry.ex index 2c8bdb4..ebf0024 100644 --- a/lib/avrogen/schema/schema_registry.ex +++ b/lib/avrogen/schema/schema_registry.ex @@ -51,7 +51,7 @@ defmodule Avrogen.Schema.SchemaRegistry do formatted_error = Exception.format(:error, e, __STACKTRACE__) Logger.error( - "Error when attempting to make encoder/decoder: #{formatted_error}; schemas: #{inspect(schemas, limit: :infinity, pretty: true, printable_limit: :infinity)} schemas_json: #{elem(json, 1)}", + "Error when attempting to make encoder/decoder: #{formatted_error}; schemas: #{inspect(schemas, limit: :infinity, pretty: true, printable_limit: :infinity)} schemas_json: #{json}", %{ error: formatted_error, schemas: schemas, From c9cf847c447b95089569f1a0c34c0d502a983efc Mon Sep 17 00:00:00 2001 From: Patrick Tschorn Date: Mon, 4 Nov 2024 15:37:08 +0000 Subject: [PATCH 7/8] remove redundant info --- lib/avrogen/schema/schema_registry.ex | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/avrogen/schema/schema_registry.ex b/lib/avrogen/schema/schema_registry.ex index ebf0024..7e90eee 100644 --- a/lib/avrogen/schema/schema_registry.ex +++ b/lib/avrogen/schema/schema_registry.ex @@ -40,9 +40,8 @@ defmodule Avrogen.Schema.SchemaRegistry do end) |> Avrogen.Schema.topological_sort() |> Noether.Either.map(fn schemas -> - json = Jason.encode!(schemas) - try do + json = Jason.encode!(schemas) encoder = make_encoder(json) decoder = make_decoder(json) :ets.insert(__MODULE__, {@ets_name, json, encoder, decoder}) @@ -51,11 +50,10 @@ defmodule Avrogen.Schema.SchemaRegistry do formatted_error = Exception.format(:error, e, __STACKTRACE__) Logger.error( - "Error when attempting to make encoder/decoder: #{formatted_error}; schemas: #{inspect(schemas, limit: :infinity, pretty: true, printable_limit: :infinity)} schemas_json: #{json}", + "Error when attempting to make encoder/decoder: #{formatted_error}; schemas: #{inspect(schemas, limit: :infinity, pretty: true, printable_limit: :infinity)}", %{ error: formatted_error, - schemas: schemas, - schemas_json: json + schemas: schemas } ) From c2cb3d469f1bf4409cd8e74b913af824de407bdd Mon Sep 17 00:00:00 2001 From: Patrick Tschorn Date: Mon, 4 Nov 2024 16:17:22 +0000 Subject: [PATCH 8/8] bumped version --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 1a877c1..eb58429 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Avrogen.MixProject do use Mix.Project - @version "0.7.2" + @version "0.7.3" @source_url "https://github.com/primait/avrogen" def project do