diff --git a/docs/error-states-verification.md b/docs/error-states-verification.md
index b496ddd..32b99a5 100644
--- a/docs/error-states-verification.md
+++ b/docs/error-states-verification.md
@@ -1,7 +1,9 @@
# Error-state verification
The #162 checklist, walked on 2026-11-13 against a local production-like build.
-Failures are filed as #171; this page is linked from the audit.
+Failures were filed as #171 and fixed in the follow-up for that issue; this page
+records the verification run, not the current state. It is linked from the
+audit.
## Method
diff --git a/lib/chesstrainer_web/components/layouts.ex b/lib/chesstrainer_web/components/layouts.ex
index 90699ac..9cf38bb 100644
--- a/lib/chesstrainer_web/components/layouts.ex
+++ b/lib/chesstrainer_web/components/layouts.ex
@@ -282,6 +282,17 @@ defmodule ChesstrainerWeb.Layouts do
{gettext("Attempting to reconnect")}
<.icon name="hero-arrow-path" class="ml-1 size-3 motion-safe:animate-spin" />
+
+
+
Reload
+ <.link href={~p"/"} class="text-muted hover:underline">Home
+
"""
end
diff --git a/lib/chesstrainer_web/controllers/page_html.ex b/lib/chesstrainer_web/controllers/page_html.ex
index 3894f51..5fbc780 100644
--- a/lib/chesstrainer_web/controllers/page_html.ex
+++ b/lib/chesstrainer_web/controllers/page_html.ex
@@ -8,6 +8,6 @@ defmodule ChesstrainerWeb.PageHTML do
embed_templates "page_html/*"
- defp play_path(nil), do: ~p"/endgames"
+ defp play_path(nil), do: ~p"/guest-train"
defp play_path(%{public_code: public_code}), do: ~p"/endgames/#{public_code}/play"
end
diff --git a/lib/chesstrainer_web/controllers/page_html/home.html.heex b/lib/chesstrainer_web/controllers/page_html/home.html.heex
index 2e4f095..95aeafa 100644
--- a/lib/chesstrainer_web/controllers/page_html/home.html.heex
+++ b/lib/chesstrainer_web/controllers/page_html/home.html.heex
@@ -12,9 +12,15 @@
Train your intuition to find the winning moves under pressure. Puzzle sessions focused purely on technical execution.
- <.pill_button variant={:primary} navigate={play_path(@active_endgame)}>
- Try today's puzzle <.icon_arrow />
-
+ <%= if @active_endgame do %>
+ <.pill_button variant={:primary} navigate={play_path(@active_endgame)}>
+ Try today's puzzle <.icon_arrow />
+
+ <% else %>
+ <.pill_button variant={:primary} navigate={play_path(nil)}>
+ Start training <.icon_arrow />
+
+ <% end %>
♟
diff --git a/lib/chesstrainer_web/controllers/user_confirmation_controller.ex b/lib/chesstrainer_web/controllers/user_confirmation_controller.ex
index a4aba73..4b717c7 100644
--- a/lib/chesstrainer_web/controllers/user_confirmation_controller.ex
+++ b/lib/chesstrainer_web/controllers/user_confirmation_controller.ex
@@ -15,8 +15,11 @@ defmodule ChesstrainerWeb.UserConfirmationController do
:error ->
conn
- |> put_flash(:error, "User not found or token is invalid.")
- |> redirect(to: ~p"/users/register")
+ |> put_flash(
+ :error,
+ "That confirmation link is invalid or has expired. Log in to request a new one."
+ )
+ |> redirect(to: ~p"/users/log-in")
end
end
end
diff --git a/lib/chesstrainer_web/controllers/user_data_controller.ex b/lib/chesstrainer_web/controllers/user_data_controller.ex
index 5e128fe..74c5209 100644
--- a/lib/chesstrainer_web/controllers/user_data_controller.ex
+++ b/lib/chesstrainer_web/controllers/user_data_controller.ex
@@ -1,7 +1,10 @@
defmodule ChesstrainerWeb.UserDataController do
use ChesstrainerWeb, :controller
+ require Logger
+
alias Chesstrainer.Attempts
+ alias Chesstrainer.Branding
@user_columns ~w(user_username user_email user_rating user_rating_deviation user_plan user_joined_at)
@attempt_columns ~w(played_at puzzle public_code color result outcome rated_at)
@@ -9,16 +12,41 @@ defmodule ChesstrainerWeb.UserDataController do
def export(conn, %{"format" => format}) when format in ["csv", "json"] do
user = conn.assigns.current_scope.user
- attempts = Attempts.list_attempts_for_user(user.id)
- filename = "lucid-chess-data-#{Date.utc_today()}.#{format}"
- conn
- |> put_resp_content_type(content_type(format))
- |> put_resp_header("content-disposition", ~s(attachment; filename="#{filename}"))
- |> send_resp(200, body(format, user, attempts))
+ try do
+ attempts = Attempts.list_attempts_for_user(user.id)
+ filename = "lucid-chess-data-#{Date.utc_today()}.#{format}"
+
+ conn
+ |> put_resp_content_type(content_type(format))
+ |> put_resp_header("content-disposition", ~s(attachment; filename="#{filename}"))
+ |> send_resp(200, body(format, user, attempts))
+ rescue
+ exception ->
+ export_failed(conn, Exception.message(exception))
+ catch
+ :exit, reason ->
+ export_failed(conn, inspect(reason))
+ end
end
- def export(conn, _params), do: send_resp(conn, 404, "Unknown export format")
+ def export(conn, _params) do
+ conn
+ |> put_status(:not_found)
+ |> put_view(ChesstrainerWeb.ErrorHTML)
+ |> render("404.html")
+ end
+
+ defp export_failed(conn, reason) do
+ Logger.error("profile.export_failed", reason: reason)
+
+ conn
+ |> put_flash(
+ :error,
+ "We couldn't build your export. Try again; if it keeps failing, email #{Branding.support_email()}."
+ )
+ |> redirect(to: ~p"/users/profile/data")
+ end
defp body("csv", user, attempts), do: to_csv(user, attempts)
diff --git a/lib/chesstrainer_web/live/endgame_live/import.ex b/lib/chesstrainer_web/live/endgame_live/import.ex
index f1d77b3..a7eed72 100644
--- a/lib/chesstrainer_web/live/endgame_live/import.ex
+++ b/lib/chesstrainer_web/live/endgame_live/import.ex
@@ -8,6 +8,8 @@ defmodule ChesstrainerWeb.EndgameLive.Import do
use ChesstrainerWeb, :live_view
+ require Logger
+
alias Chesstrainer.Endgames.BulkImport
alias Chesstrainer.Endgames.Tablebase.Local
@@ -268,7 +270,14 @@ defmodule ChesstrainerWeb.EndgameLive.Import do
end
def handle_async(:lookup, {:exit, reason}, socket) do
- {:noreply, put_flash(socket, :error, "Could not look up the FENs: #{inspect(reason)}")}
+ Logger.error("bulk_import.lookup_failed", reason: inspect(reason))
+
+ {:noreply,
+ put_flash(
+ socket,
+ :error,
+ "The lookup failed. Try again; if it keeps happening, check the server log."
+ )}
end
defp tablebase_status do
@@ -284,7 +293,8 @@ defmodule ChesstrainerWeb.EndgameLive.Import do
{:error, "Local tablebase is not configured. Set TABLEBASE_PATH to enable imports."}
{:error, reason} ->
- {:error, "Local tablebase failed to load: #{inspect(reason)}"}
+ Logger.warning("bulk_import.tablebase_unavailable", reason: inspect(reason))
+ {:error, "The local tablebase failed to load. Check TABLEBASE_PATH and the server log."}
end
end
diff --git a/lib/chesstrainer_web/live/endgame_live/play_core.ex b/lib/chesstrainer_web/live/endgame_live/play_core.ex
index 4746e85..fb2cd01 100644
--- a/lib/chesstrainer_web/live/endgame_live/play_core.ex
+++ b/lib/chesstrainer_web/live/endgame_live/play_core.ex
@@ -197,12 +197,10 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
end
def fen_invalid(socket, %{"fen" => fen, "message" => message}) do
+ Logger.warning("board.fen_invalid", fen: fen, message: message)
+
{:noreply,
- put_flash(
- socket,
- :error,
- "Endgame FEN is invalid and the board cannot be loaded: #{message} (#{fen})"
- )}
+ put_flash(socket, :error, "The board couldn't load this position. Reset to try again.")}
end
def reset(socket) do
diff --git a/test/chesstrainer_web/controllers/page_controller_test.exs b/test/chesstrainer_web/controllers/page_controller_test.exs
index 986ceec..57da032 100644
--- a/test/chesstrainer_web/controllers/page_controller_test.exs
+++ b/test/chesstrainer_web/controllers/page_controller_test.exs
@@ -61,7 +61,7 @@ defmodule ChesstrainerWeb.PageControllerTest do
assert html =~ "menu-button"
assert html =~ ~s(class="site-footer")
assert html =~ "© #{DateTime.utc_now().year} #{Branding.name()}"
- assert html =~ ~p"/endgames"
+ assert html =~ ~p"/guest-train"
assert html =~ "/assets/js/marketing.js"
refute html =~ "/assets/js/app.js"
@@ -318,6 +318,9 @@ defmodule ChesstrainerWeb.PageControllerTest do
end
test "renders without endgames", %{conn: conn} do
+ previous = Application.get_env(:chesstrainer, :curated_endgame_codes)
+ on_exit(fn -> Application.put_env(:chesstrainer, :curated_endgame_codes, previous) end)
+
Application.put_env(:chesstrainer, :curated_endgame_codes, [])
html = conn |> get(~p"/") |> html_response(200)
@@ -327,8 +330,10 @@ defmodule ChesstrainerWeb.PageControllerTest do
refute html =~ "puzzle-card"
assert LazyHTML.attribute(LazyHTML.query(document, ".hero-actions a"), "href") == [
- "/endgames"
+ "/guest-train"
]
+
+ assert html =~ "Start training"
end
test "unknown routes render the branded 404 page", %{conn: conn} do
diff --git a/test/chesstrainer_web/controllers/user_confirmation_controller_test.exs b/test/chesstrainer_web/controllers/user_confirmation_controller_test.exs
index bdeb2c2..9d09d6a 100644
--- a/test/chesstrainer_web/controllers/user_confirmation_controller_test.exs
+++ b/test/chesstrainer_web/controllers/user_confirmation_controller_test.exs
@@ -31,9 +31,9 @@ defmodule ChesstrainerWeb.UserConfirmationControllerTest do
conn = get(conn, ~p"/users/confirm/oops")
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
- "User not found or token is invalid."
+ "That confirmation link is invalid or has expired. Log in to request a new one."
- assert redirected_to(conn) == ~p"/users/register"
+ assert redirected_to(conn) == ~p"/users/log-in"
end
test "confirms a linked mailing-list opt-in", %{conn: conn, user: user} do
diff --git a/test/chesstrainer_web/controllers/user_data_controller_test.exs b/test/chesstrainer_web/controllers/user_data_controller_test.exs
index 558e9c0..a13a012 100644
--- a/test/chesstrainer_web/controllers/user_data_controller_test.exs
+++ b/test/chesstrainer_web/controllers/user_data_controller_test.exs
@@ -21,6 +21,15 @@ defmodule ChesstrainerWeb.UserDataControllerTest do
assert redirected_to(conn) == ~p"/users/log-in"
end
+ test "returns the styled 404 page for an unknown format", %{conn: conn} do
+ conn = get(conn, ~p"/users/profile/export/xml")
+
+ html = html_response(conn, 404)
+ assert html =~ "This page isn't on the board"
+ assert html =~ "Back to home"
+ assert get_resp_header(conn, "content-type") == ["text/html; charset=utf-8"]
+ end
+
test "downloads the user details and attempts as CSV", %{
conn: conn,
user: user,
diff --git a/test/chesstrainer_web/live/endgame_live/play_test.exs b/test/chesstrainer_web/live/endgame_live/play_test.exs
index a3de5b6..4d2a888 100644
--- a/test/chesstrainer_web/live/endgame_live/play_test.exs
+++ b/test/chesstrainer_web/live/endgame_live/play_test.exs
@@ -326,6 +326,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
end
describe "chess_fen_invalid" do
+ @tag capture_log: true
test "shows a flash when the chessground hook reports an unparseable FEN", %{conn: conn} do
endgame = endgame_fixture()
seed_tablebase(endgame.fen)
@@ -339,8 +340,9 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
})
html = render(view)
- assert html =~ "Endgame FEN is invalid"
- assert html =~ "move number must be a positive integer"
+ assert html =~ "The board couldn't load this position. Reset to try again."
+ refute html =~ "Endgame FEN is invalid"
+ refute html =~ "move number must be a positive integer"
end
end
diff --git a/test/chesstrainer_web/live/endgame_live/train_test.exs b/test/chesstrainer_web/live/endgame_live/train_test.exs
index 742a4fe..6e5d887 100644
--- a/test/chesstrainer_web/live/endgame_live/train_test.exs
+++ b/test/chesstrainer_web/live/endgame_live/train_test.exs
@@ -88,6 +88,8 @@ defmodule ChesstrainerWeb.EndgameLive.TrainTest do
assert has_element?(view, "#difficulty-hard")
assert has_element?(view, "#close-difficulty[href='/']")
assert has_element?(view, "a", "Return Home")
+ assert has_element?(view, "#connection-actions")
+ assert render(view) =~ ">Reload<"
refute has_element?(view, "#puzzle-search")
assert has_element?(view, "#rating-guide")
assert render(view) =~ "Choose a difficulty"