Errors: replies and flashes say what went wrong, not the term

3db9f38 · Gabriel Morell · 2026-10-20 20:29

39 files +194 -57
Message
{commit_body(@commit)}

Files changed

modified lib/git_gud_web/controllers/actions_artifact_controller.ex
+2 −1
@@ -28,6 +28,7 @@ defmodule GitGudWeb.ActionsArtifactController do
28 28 alias GitGud.Repo
29 29 alias GitGud.Storage
30 30 alias GitGud.Workflows.WorkflowArtifact
31 + alias GitGudWeb.ErrorMessage
31 32
32 33 @bucket "gitgud-artifacts"
33 34
@@ -96,7 +97,7 @@ defmodule GitGudWeb.ActionsArtifactController do
96 97 {:error, reason} ->
97 98 conn
98 99 |> put_resp_content_type("application/json", nil)
99 − |> send_resp(500, Jason.encode!(%{"error" => inspect(reason)}))
100 + |> send_resp(500, Jason.encode!(%{"error" => ErrorMessage.describe(reason)}))
100 101 end
101 102 end
102 103
modified lib/git_gud_web/controllers/actions_cache_controller.ex
+2 −1
@@ -23,6 +23,7 @@ defmodule GitGudWeb.ActionsCacheController do
23 23 alias GitGud.Repositories
24 24 alias GitGud.Workflows.ActionsCache
25 25 alias GitGud.Workflows.CacheEntry
26 + alias GitGudWeb.ErrorMessage
26 27
27 28 def get_cache(conn, params) do
28 29 repo_id = jwt_repo_id(conn)
@@ -163,7 +164,7 @@ defmodule GitGudWeb.ActionsCacheController do
163 164 defp error_resp(conn, {:error, reason}) do
164 165 conn
165 166 |> put_resp_content_type("application/json", nil)
166 − |> send_resp(500, Jason.encode!(%{"error" => inspect(reason)}))
167 + |> send_resp(500, Jason.encode!(%{"error" => ErrorMessage.describe(reason)}))
167 168 end
168 169
169 170 defp jwt_job_id(conn) do
modified lib/git_gud_web/controllers/api/mobile/ci_controller.ex
+5 −4
@@ -15,6 +15,7 @@ defmodule GitGudWeb.Api.Mobile.CiController do
15 15 alias GitGud.Workflows
16 16 alias GitGudWeb.Api.Mobile.Auth
17 17 alias GitGudWeb.Api.Mobile.JSON
18 + alias GitGudWeb.ErrorMessage
18 19
19 20 # A phone can't usefully show more than this, and a chatty job can
20 21 # emit six figures of lines.
@@ -88,7 +89,7 @@ defmodule GitGudWeb.Api.Mobile.CiController do
88 89 send_error(conn, 422, changeset_message(cs))
89 90
90 91 {:error, reason} ->
91 − send_error(conn, 422, inspect(reason))
92 + send_error(conn, 422, ErrorMessage.describe(reason))
92 93 end
93 94 else
94 95 {:error, conn} -> conn
@@ -108,7 +109,7 @@ defmodule GitGudWeb.Api.Mobile.CiController do
108 109 case Workflows.rerun_job(run, job) do
109 110 {:ok, _} -> json(conn, reloaded(repo, n))
110 111 {:error, :not_found} -> send_error(conn, 404, "no job '#{job}' in run ##{n}")
111 − {:error, reason} -> send_error(conn, 422, inspect(reason))
112 + {:error, reason} -> send_error(conn, 422, ErrorMessage.describe(reason))
112 113 end
113 114 else
114 115 {:error, conn} -> conn
@@ -122,7 +123,7 @@ defmodule GitGudWeb.Api.Mobile.CiController do
122 123 {:ok, run} <- get_run(conn, repo, n) do
123 124 case Workflows.cancel(run) do
124 125 {:ok, _} -> json(conn, reloaded(repo, n))
125 − {:error, reason} -> send_error(conn, 422, inspect(reason))
126 + {:error, reason} -> send_error(conn, 422, ErrorMessage.describe(reason))
126 127 end
127 128 else
128 129 {:error, conn} -> conn
@@ -196,7 +197,7 @@ defmodule GitGudWeb.Api.Mobile.CiController do
196 197 send_error(conn, 422, changeset_message(cs))
197 198
198 199 {:error, reason} ->
199 − send_error(conn, 422, inspect(reason))
200 + send_error(conn, 422, ErrorMessage.describe(reason))
200 201 end
201 202 else
202 203 {:error, conn} -> conn
modified lib/git_gud_web/controllers/api/mobile/pull_request_controller.ex
+8 −3
@@ -37,6 +37,7 @@ defmodule GitGudWeb.Api.Mobile.PullRequestController do
37 37 alias GitGud.PullRequests.PrReview
38 38 alias GitGudWeb.Api.Mobile.Auth
39 39 alias GitGudWeb.Api.Mobile.JSON
40 + alias GitGudWeb.ErrorMessage
40 41
41 42 def index(conn, %{"owner" => owner, "name" => name} = params) do
42 43 with {:ok, user} <- Auth.require_scope(conn, "pulls:read"),
@@ -103,7 +104,11 @@ defmodule GitGudWeb.Api.Mobile.PullRequestController do
103 104 send_error(conn, 422, changeset_message(cs))
104 105
105 106 {:error, reason} ->
106 − send_error(conn, 422, "could not open the pull request: #{inspect(reason)}")
107 + send_error(
108 + conn,
109 + 422,
110 + "could not open the pull request: #{ErrorMessage.describe(reason)}"
111 + )
107 112 end
108 113 else
109 114 {:error, conn} -> conn
@@ -294,7 +299,7 @@ defmodule GitGudWeb.Api.Mobile.PullRequestController do
294 299 send_error(conn, 422, changeset_message(cs))
295 300
296 301 {:error, reason} ->
297 − send_error(conn, 422, inspect(reason))
302 + send_error(conn, 422, ErrorMessage.describe(reason))
298 303 end
299 304 else
300 305 {:error, conn} -> conn
@@ -326,7 +331,7 @@ defmodule GitGudWeb.Api.Mobile.PullRequestController do
326 331 send_error(conn, 409, "the target branch moved while merging — try again")
327 332
328 333 {:error, reason} ->
329 − send_error(conn, 422, inspect(reason))
334 + send_error(conn, 422, ErrorMessage.describe(reason))
330 335 end
331 336 else
332 337 {:error, conn} -> conn
modified lib/git_gud_web/controllers/api/v1/org_controller.ex
+2 −1
@@ -19,6 +19,7 @@ defmodule GitGudWeb.Api.V1.OrgController do
19 19 alias GitGud.Accounts
20 20 alias GitGud.Organizations
21 21 alias GitGud.Repositories
22 + alias GitGudWeb.ErrorMessage
22 23
23 24 def create_repo(conn, %{"org" => handle} = params) do
24 25 with {:ok, user} <- authenticate(conn, "repo"),
@@ -45,7 +46,7 @@ defmodule GitGudWeb.Api.V1.OrgController do
45 46 send_error(conn, 422, changeset_message(cs))
46 47
47 48 {:error, reason} ->
48 − send_error(conn, 422, inspect(reason))
49 + send_error(conn, 422, ErrorMessage.describe(reason))
49 50 end
50 51 else
51 52 :error -> send_error(conn, 401, "invalid token or missing 'repo' scope")
modified lib/git_gud_web/controllers/api/v1/workflow_controller.ex
+2 −1

Click to load diff…

modified lib/git_gud_web/controllers/package_registry_controller.ex
+2 −1

Click to load diff…

modified lib/git_gud_web/controllers/pre_receive_controller.ex
+2 −1

Click to load diff…

modified lib/git_gud_web/controllers/registry_controller.ex
+4 −1

Click to load diff…

modified lib/git_gud_web/controllers/runner_controller.ex
+6 −5

Click to load diff…

modified lib/git_gud_web/controllers/webauthn_controller.ex
+4 −3

Click to load diff…

added lib/git_gud_web/error_message.ex
+61 −0

Click to load diff…

modified lib/git_gud_web/live/avatar_upload.ex
+3 −2

Click to load diff…

modified lib/git_gud_web/live/import_live/new.ex
+5 −3

Click to load diff…

modified lib/git_gud_web/live/pr_live/files.ex
+2 −1

Click to load diff…

modified lib/git_gud_web/live/pr_live/new.ex
+6 −3

Click to load diff…

modified lib/git_gud_web/live/pr_live/show.ex
+2 −1

Click to load diff…

modified lib/git_gud_web/live/repo_live/fork.ex
+3 −11

Click to load diff…

modified lib/git_gud_web/live/repo_live/merge.ex
+9 −4

Click to load diff…

modified lib/git_gud_web/live/repo_live/new.ex
+7 −1

Click to load diff…

modified lib/git_gud_web/live/repo_live/settings.ex
+3 −2

Click to load diff…

modified lib/git_gud_web/live/repo_live/show.ex
+2 −1

Click to load diff…

modified lib/git_gud_web/live/wiki_live/edit.ex
+2 −1

Click to load diff…

modified lib/git_gud_web/live/workflow_live/show.ex
+9 −5

Click to load diff…

added test/git_gud_web/error_message_test.exs
+41 −0

Click to load diff…

Parents: 3d1b0af