fix: return error tuples instead of silent {:ok, ""} in execute_macro (CSM-022)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-11 09:07:44 +02:00
parent 2be43ca06d
commit a4ecbabc21
3 changed files with 12 additions and 6 deletions

View File

@@ -360,10 +360,12 @@
--- ---
### CSM-022 — Silent Error Swallowing ### ~~CSM-022 — Silent Error Swallowing~~ ✅ FIXED
- **File:** `lib/bds/scripting.ex:64-66` - **Fixed:** 2026-05-11
- **What:** `execute_macro/4` returns `{:ok, ""}` on `{:error, _reason}` with no logging. The caller cannot distinguish success from failure. - **What was done:**
- **Fix:** Return the actual error tuple or at least log the failure with `Logger.error/1`. - `execute_macro/4` now returns `{:error, reason}` instead of `{:ok, ""}` when the underlying script execution fails.
- Added `Logger.warning/1` call that logs the project ID and error reason before returning the error tuple.
- Updated test in `api_test.exs` to assert `{:error, _reason}` instead of `{:ok, ""}` for failing macros.
--- ---

View File

@@ -3,6 +3,8 @@ defmodule BDS.Scripting do
Facade for the configured user-script runtime. Facade for the configured user-script runtime.
""" """
require Logger
alias BDS.Scripting.Capabilities alias BDS.Scripting.Capabilities
alias BDS.Scripting.Runtime alias BDS.Scripting.Runtime
@@ -63,7 +65,9 @@ defmodule BDS.Scripting do
) do ) do
{:ok, nil} -> {:ok, ""} {:ok, nil} -> {:ok, ""}
{:ok, value} -> {:ok, to_string(value)} {:ok, value} -> {:ok, to_string(value)}
{:error, _reason} -> {:ok, ""} {:error, reason} ->
Logger.warning("execute_macro failed for project #{project_id}: #{inspect(reason)}")
{:error, reason}
end end
end end

View File

@@ -106,7 +106,7 @@ defmodule BDS.Scripting.ApiTest do
bad_source = "function render() error('boom') end" bad_source = "function render() error('boom') end"
assert {:ok, ""} = BDS.Scripting.execute_macro(project.id, bad_source, []) assert {:error, _reason} = BDS.Scripting.execute_macro(project.id, bad_source, [])
end end
test "project scripting exposes project, post, script, template, metadata, and task namespaces", test "project scripting exposes project, post, script, template, metadata, and task namespaces",