Packages
Multi-surface application runtime for Elixir. One TEA module renders to terminal, browser (LiveView), SSH, and MCP (agents). 30+ widgets, flexbox + CSS grid, AI agent runtime, distributed swarm with CRDTs, time-travel debugging, session recording, sandboxed REPL, and agentic commerce.
Current section
Files
Jump to
Current section
Files
lib/raxol_web/error_helpers.ex
defmodule RaxolWeb.ErrorHelpers do
require Logger
import Phoenix.Component, only: [assign: 2, assign: 3]
import Phoenix.LiveView, only: [put_flash: 3]
@doc """
Handles LiveView errors consistently across the application.
"""
def handle_live_view_error(socket, error, fallback_assigns \\ %{}) do
Logger.error("LiveView error: #{inspect(error)}")
socket
|> put_flash(:error, "An unexpected error occurred")
|> assign(fallback_assigns)
end
@doc """
Safely assigns a value to the socket, handling errors gracefully.
"""
def safe_assign(socket, key, value_fn) when is_function(value_fn) do
try do
assign(socket, key, value_fn.())
rescue
error ->
Logger.error("Error assigning #{key}: #{inspect(error)}")
assign(socket, key, nil)
end
end
@doc """
Creates a standardized error response for forms.
"""
def create_form_error_response(socket, field, message, error_text) do
socket
|> put_flash(:error, message)
|> assign(:changeset, %{
errors: [{field, {error_text, []}}]
})
end
@doc """
Handles channel errors consistently.
"""
def handle_channel_error(socket, error, context \\ %{}) do
Logger.error("Channel error in #{context[:module]}: #{inspect(error)}")
case error do
:rate_limited ->
{:reply, {:error, %{reason: "rate_limited"}}, socket}
:invalid_input ->
{:reply, {:error, %{reason: "invalid_input"}}, socket}
_ ->
{:reply, {:error, %{reason: "internal_error"}}, socket}
end
end
end