aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-05-11 12:51:04 +0200
committerGitHub <[email protected]>2017-05-11 12:51:04 +0200
commitc3a81d86c0ad0245cd47ff17aee70dc816c07e39 (patch)
treef21ea993bd379ebb960bc896c15532aae9e00f09
parent5aa7180ae0ad7a34d1903003cbcd4a7d5cc61858 (diff)
parent5d7e12f4d037f74602029850bbd29e38c3732b48 (diff)
downloadotp-c3a81d86c0ad0245cd47ff17aee70dc816c07e39.tar.gz
otp-c3a81d86c0ad0245cd47ff17aee70dc816c07e39.tar.bz2
otp-c3a81d86c0ad0245cd47ff17aee70dc816c07e39.zip
Merge pull request #1449 from bjorng/bjorn/future-proof-exceptions
Make calls to get_stacktrace/0 future-proof OTP-14400
-rw-r--r--lib/common_test/src/ct_run.erl26
-rw-r--r--lib/common_test/src/ct_util.erl9
-rw-r--r--lib/snmp/src/agent/snmp_generic.erl28
-rw-r--r--lib/stdlib/src/qlc.erl6
4 files changed, 37 insertions, 32 deletions
diff --git a/lib/common_test/src/ct_run.erl b/lib/common_test/src/ct_run.erl
index bbace18a28..ce30babc0d 100644
--- a/lib/common_test/src/ct_run.erl
+++ b/lib/common_test/src/ct_run.erl
@@ -436,13 +436,17 @@ script_start2(Opts = #opts{vts = undefined,
Specs1 = get_start_opt(join_specs, [Specs], Specs, Args),
%% using testspec as input for test
Relaxed = get_start_opt(allow_user_terms, true, false, Args),
- case catch ct_testspec:collect_tests_from_file(Specs1, Relaxed) of
- {E,Reason} when E == error ; E == 'EXIT' ->
+ try ct_testspec:collect_tests_from_file(Specs1, Relaxed) of
+ TestSpecData ->
+ execute_all_specs(TestSpecData, Opts, Args, [])
+ catch
+ throw:{error,Reason} ->
StackTrace = erlang:get_stacktrace(),
{error,{invalid_testspec,{Reason,StackTrace}}};
- TestSpecData ->
- execute_all_specs(TestSpecData, Opts, Args, [])
- end;
+ _:Reason ->
+ StackTrace = erlang:get_stacktrace(),
+ {error,{invalid_testspec,{Reason,StackTrace}}}
+ end;
[] ->
{error,no_testspec_specified};
_ -> % no testspec used
@@ -1198,12 +1202,16 @@ run_spec_file(Relaxed,
end,
AbsSpecs = lists:map(fun(SF) -> ?abs(SF) end, Specs1),
AbsSpecs1 = get_start_opt(join_specs, [AbsSpecs], AbsSpecs, StartOpts),
- case catch ct_testspec:collect_tests_from_file(AbsSpecs1, Relaxed) of
- {Error,CTReason} when Error == error ; Error == 'EXIT' ->
- StackTrace = erlang:get_stacktrace(),
- exit({error,{invalid_testspec,{CTReason,StackTrace}}});
+ try ct_testspec:collect_tests_from_file(AbsSpecs1, Relaxed) of
TestSpecData ->
run_all_specs(TestSpecData, Opts, StartOpts, [])
+ catch
+ throw:{error,CTReason} ->
+ StackTrace = erlang:get_stacktrace(),
+ exit({error,{invalid_testspec,{CTReason,StackTrace}}});
+ _:CTReason ->
+ StackTrace = erlang:get_stacktrace(),
+ exit({error,{invalid_testspec,{CTReason,StackTrace}}})
end.
run_all_specs([], _, _, TotResult) ->
diff --git a/lib/common_test/src/ct_util.erl b/lib/common_test/src/ct_util.erl
index 4d3a2ae7e3..802e9be97c 100644
--- a/lib/common_test/src/ct_util.erl
+++ b/lib/common_test/src/ct_util.erl
@@ -201,14 +201,7 @@ do_start(Parent, Mode, LogDir, Verbosity) ->
ok ->
Parent ! {self(),started};
{fail,CTHReason} ->
- ErrorInfo = if is_atom(CTHReason) ->
- io_lib:format("{~p,~p}",
- [CTHReason,
- erlang:get_stacktrace()]);
- true ->
- CTHReason
- end,
- ct_logs:tc_print('Suite Callback',ErrorInfo,[]),
+ ct_logs:tc_print('Suite Callback',CTHReason,[]),
self() ! {{stop,{self(),{user_error,CTHReason}}},
{Parent,make_ref()}}
catch
diff --git a/lib/snmp/src/agent/snmp_generic.erl b/lib/snmp/src/agent/snmp_generic.erl
index fc23e16ef1..4738525341 100644
--- a/lib/snmp/src/agent/snmp_generic.erl
+++ b/lib/snmp/src/agent/snmp_generic.erl
@@ -413,20 +413,21 @@ table_check_status(NameDb, Col, ?'RowStatus_createAndGo', RowIndex, Cols) ->
false ->
% it's ok to use snmpa_local_db:table_construct_row since it's
% side effect free and we only use the result temporary.
- case catch snmpa_local_db:table_construct_row(
+ try snmpa_local_db:table_construct_row(
NameDb, RowIndex, ?'RowStatus_createAndGo', Cols) of
- {'EXIT', _Reason} ->
- ?vtrace(
- "failed construct row (createAndGo): "
- " n Reason: ~p"
- " n Stack: ~p",
- [_Reason, erlang:get_stacktrace()]),
- {noCreation, Col}; % Bad RowIndex
Row ->
case lists:member(noinit, tuple_to_list(Row)) of
false -> {noError, 0};
_Found -> {inconsistentValue, Col}
end
+ catch
+ _:_Reason ->
+ ?vtrace(
+ "failed construct row (createAndGo): "
+ " n Reason: ~p"
+ " n Stack: ~p",
+ [_Reason, erlang:get_stacktrace()]),
+ {noCreation, Col} % Bad RowIndex
end;
true -> {inconsistentValue, Col}
end;
@@ -435,17 +436,18 @@ table_check_status(NameDb, Col, ?'RowStatus_createAndGo', RowIndex, Cols) ->
table_check_status(NameDb, Col, ?'RowStatus_createAndWait', RowIndex, Cols) ->
case table_row_exists(NameDb, RowIndex) of
false ->
- case catch snmpa_local_db:table_construct_row(
+ try snmpa_local_db:table_construct_row(
NameDb, RowIndex, ?'RowStatus_createAndGo', Cols) of
- {'EXIT', _Reason} ->
+ _Row ->
+ {noError, 0}
+ catch
+ _:_Reason ->
?vtrace(
"failed construct row (createAndWait): "
" n Reason: ~p"
" n Stack: ~p",
[_Reason, erlang:get_stacktrace()]),
- {noCreation, Col}; % Bad RowIndex
- _Row ->
- {noError, 0}
+ {noCreation, Col} % Bad RowIndex
end;
true -> {inconsistentValue, Col}
end;
diff --git a/lib/stdlib/src/qlc.erl b/lib/stdlib/src/qlc.erl
index 20aaa2638c..535ca57a6b 100644
--- a/lib/stdlib/src/qlc.erl
+++ b/lib/stdlib/src/qlc.erl
@@ -1392,8 +1392,10 @@ next_loop(Pid, L, N) when N =/= 0 ->
{caught, throw, Error, [?THROWN_ERROR | _]} ->
Error;
{caught, Class, Reason, Stacktrace} ->
- _ = (catch erlang:error(foo)),
- erlang:raise(Class, Reason, Stacktrace ++ erlang:get_stacktrace());
+ CurrentStacktrace = try erlang:error(foo)
+ catch error:_ -> erlang:get_stacktrace()
+ end,
+ erlang:raise(Class, Reason, Stacktrace ++ CurrentStacktrace);
error ->
erlang:error({qlc_cursor_pid_no_longer_exists, Pid})
end;