File 0721-CT-Add-source-filename-in-error-output-when-possible.patch of Package erlang
From df73e4a6e7ccec31de2388343e7aabdb0c7506f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= <essen@ninenines.eu>
Date: Wed, 8 Oct 2025 16:51:43 +0200
Subject: [PATCH 1/4] CT: Add source filename in error output when possible
---
lib/common_test/src/ct_framework.erl | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/lib/common_test/src/ct_framework.erl b/lib/common_test/src/ct_framework.erl
index 242fd3ce1e..18ec9faae8 100644
--- a/lib/common_test/src/ct_framework.erl
+++ b/lib/common_test/src/ct_framework.erl
@@ -25,6 +25,8 @@
-module(ct_framework).
+-feature(maybe_expr, enable).
+
-export([init_tc/3, end_tc/3, end_tc/4, get_suite/2, get_all_cases/1]).
-export([report/2, warn/1, error_notification/4]).
@@ -1013,17 +1013,21 @@ error_notification(Mod,Func,_Args,{Error,Loc}) ->
%% if a function specified by all/0 does not exist, we
%% pick up undef here
[{LastMod,LastFunc}|_] when ErrorStr == "undef" ->
- PrintError("~w:~tw could not be executed~nReason: ~ts",
- [LastMod,LastFunc,ErrorStr]);
+ LastSource = error_notification_source_info(LastMod),
+ PrintError("~w:~tw at ~ts could not be executed~nReason: ~ts",
+ [LastMod,LastFunc,LastSource,ErrorStr]);
[{LastMod,LastFunc}|_] ->
- PrintError("~w:~tw failed~nReason: ~ts", [LastMod,LastFunc,ErrorStr]);
+ LastSource = error_notification_source_info(LastMod),
+ PrintError("~w:~tw at ~ts failed~nReason: ~ts",
+ [LastMod,LastFunc,LastSource,ErrorStr]);
[{LastMod,LastFunc,LastLine}|_] ->
%% print error to console, we are only
%% interested in the last executed expression
- PrintError("~w:~tw failed on line ~w~nReason: ~ts",
- [LastMod,LastFunc,LastLine,ErrorStr]),
+ LastSource = error_notification_source_info(LastMod),
+ PrintError("~w:~tw at ~ts:~w failed~nReason: ~ts",
+ [LastMod,LastFunc,LastSource,LastLine,ErrorStr]),
case ct_util:read_suite_data({seq,Mod,Func}) of
undefined ->
@@ -1035,6 +1039,16 @@ error_notification(Mod,Func,_Args,{Error,Loc}) ->
end,
ok.
+error_notification_source_info(Mod) ->
+ maybe
+ {Mod, Beam, _} ?= code:get_object_code(Mod),
+ {ok, {Mod, [{abstract_code, {_, Forms}}]}} ?= beam_lib:chunks(Beam, [abstract_code]),
+ [{attribute, _, file, {File, _}}|_] ?= Forms,
+ File
+ else
+ _ -> atom_to_list(Mod) ++ ".erl"
+ end.
+
%% cases in seq that have already run
mark_as_failed(Seq,Mod,Func,[Func|TCs]) ->
mark_as_failed1(Seq,Mod,Func,TCs);
--
2.51.0