Skip to content

Change level of repetitive log#324

Merged
zachdaniel merged 4 commits intoash-project:mainfrom
capoccias:fix-failed-to-display-errors
Jun 17, 2025
Merged

Change level of repetitive log#324
zachdaniel merged 4 commits intoash-project:mainfrom
capoccias:fix-failed-to-display-errors

Conversation

@capoccias
Copy link
Contributor

Hey,

I've seen a bunch of error logs like the following:

Failed to display value:
** (Protocol.UndefinedError) protocol Phoenix.HTML.Safe not implemented for type Postgrex.Range (a struct). This protocol is implemented for the following type(s): Ash.CiString, Ash.NotLoaded, Atom, BitString, Date, DateTime, Decimal, Float, Integer, List, NaiveDateTime, Phoenix.LiveComponent.CID, Phoenix.LiveView.Component, Phoenix.LiveView.Comprehension, Phoenix.LiveView.JS, Phoenix.LiveView.Rendered, Time, Tuple, URI

Got value:

    %Postgrex.Range{
      lower: ~U[2025-05-26 08:53:35.314461Z],
      upper: :unbound,
      lower_inclusive: true,
      upper_inclusive: false
    }

    (phoenix_html 4.2.1) lib/phoenix_html/safe.ex:1: Phoenix.HTML.Safe.impl_for!/1
    (phoenix_html 4.2.1) lib/phoenix_html/safe.ex:15: Phoenix.HTML.Safe.to_iodata/1
    (ash_admin 0.13.9) lib/ash_admin/components/resource/show.ex:916: AshAdmin.Components.Resource.Show.value!/1
    (ash_admin 0.13.9) lib/ash_admin/components/resource/show.ex:321: anonymous fn/2 in AshAdmin.Components.Resource.Show.render_attributes/4
    (elixir 1.18.4) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.18.4) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (ash_admin 0.13.9) lib/ash_admin/components/resource/show.ex:307: anonymous fn/2 in AshAdmin.Components.Resource.Show.render_attributes/4
    (phoenix_live_view 1.0.17) lib/phoenix_live_view/diff.ex:414: Phoenix.LiveView.Diff.traverse/7

I added specific handling the Postgrex.Range struct but also happens for others defined in my app, e.g.

    %MyApp.MyDomain.Amount{
      currency_type: :fiat,
      currency_symbol: :usd,
      value: Decimal.new("50"),
      __meta__: #Ecto.Schema.Metadata<:built, "">
    }

While minor, I figure having a quick configuration option to simply ignore these might be useful since (at least in my case) it doesn't hinder the functionality of the admin UI.

Let me know if this needs any improvements or close if not wanted :)

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

e ->
Logger.error("Failed to display value:\n#{Exception.format(:error, e, __STACKTRACE__)}")
"<display error>"
if @log_failed_to_display_value_error do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets also turn these into debug logs that way it doesn't clutter up production logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my main issue was it showing up in prod. I didn't want to change the log level since that would affect others but honestly probably makes the most sense.
I'll push up a change that removes the config and just changes to Logger.debug

import AshAdmin.Helpers
import AshAdmin.CoreComponents

@log_failed_to_display_value_error Application.compile_env(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets document this configuration somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per this: #324 (comment)
I'll remove the config but if we want it back I'll definitely document somewhere

@capoccias capoccias changed the title [idea] Add config to silence logs Change level of repetitive log Jun 17, 2025
@zachdaniel zachdaniel merged commit a6b1089 into ash-project:main Jun 17, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants