CodeStory.CleanInspect (CodeStory v0.2.0)

Copy Markdown View Source

Inspects a value, then strips Ecto bookkeeping noise from the resulting string — __meta__: #Ecto.Schema.Metadata<…> and #Ecto.Association.NotLoaded<…> — so a trace shows %Order{id: 12, status: "paid", …} instead of the full Ecto internals.

One value-shaped exception precedes the string cleaning: inspect/2 first delegates a top-level Ecto.Query value to CodeStory.QueryLabel, which renders it as a compact #Ecto.Query<Schema> label (at the summary detail levels only). Everything else follows the string-cleaning path below.

We clean the inspected string, not the value: removing __meta__ from the value pre-inspect turns the struct into a plain map (%{…, __struct__: Mod}), losing the %Mod{…} name. CodeStory has no Ecto dependency — detection is purely string-shaped.

Known limitations

Because this is string-cleaning, not value-cleaning:

  • a struct with __meta__ as its only field isn't stripped (no adjacent ,) — real schemas always have an id/fields, so this never happens in practice;
  • a NotLoaded association whose name isn't a bare identifier (\w+) isn't dropped — rare;
  • a genuine string value that literally contains the full __meta__: #Ecto.Schema.Metadata<…> field shape would be edited — the unavoidable cost of the chosen approach; low likelihood (a bare #Ecto.Schema.Metadata<…> substring, with no __meta__: prefix, is untouched);
  • under a compact :limit, stripping a NotLoaded/nested-struct field can show one fewer real field at that level (only the top-level __meta__ slot is compensated by the limit bump below).

Summary

Functions

Like Kernel.inspect/2, but with Ecto __meta__/NotLoaded noise stripped.

Inspect options for a :detail level — full values for :novel, compact otherwise. The single source of truth both the formatter and the encoder resolve :detail through.

Removes Ecto __meta__ and NotLoaded fragments from an already-inspected string.

Functions

inspect(value, opts)

@spec inspect(
  term(),
  keyword()
) :: String.t()

Like Kernel.inspect/2, but with Ecto __meta__/NotLoaded noise stripped.

opts_for(arg1)

@spec opts_for(atom()) :: keyword()

Inspect options for a :detail level — full values for :novel, compact otherwise. The single source of truth both the formatter and the encoder resolve :detail through.

strip_ecto_noise(str)

@spec strip_ecto_noise(String.t()) :: String.t()

Removes Ecto __meta__ and NotLoaded fragments from an already-inspected string.