Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/rebar/src/rebar_packages.erl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ load_and_verify_version(State) ->
%% shouldn't notice, so log as a debug message only
?DEBUG("Package index version mismatch. Current version ~p, this rebar3 expecting ~p",
[V, ?PACKAGE_INDEX_VERSION]),
(catch ets:delete(?PACKAGE_TABLE)),
try ets:delete(?PACKAGE_TABLE) catch _:_ -> ok end,
new_package_table()
end;
_ ->
Expand Down
2 changes: 1 addition & 1 deletion apps/rebar/src/rebar_pkg_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ maybe_old_registry_checksum(Hash) -> list_to_integer(binary_to_list(Hash), 16).
Binary :: binary(),
Res :: ok | {error,_}.
serve_from_download(TmpDir, CachePath, Package, Binary) ->
?DEBUG("Writing ~p to cache at ~ts", [catch anon(Package), CachePath]),
?DEBUG("Writing ~p to cache at ~ts", [try anon(Package) catch _:_ -> error end, CachePath]),
file:write_file(CachePath, Binary),
serve_from_memory(TmpDir, Binary, Package).

Expand Down
4 changes: 3 additions & 1 deletion apps/rebar/src/rebar_prv_cover.erl
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ is_ignored(Dir, File, ExclMods) ->
Ignored.

cover_compile_file(FileName) ->
case catch(cover:compile_beam(FileName)) of
case try cover:compile_beam(FileName)
catch C:R -> {'EXIT', {C, R}}
end of
{error, Reason} ->
?WARN("Cover compilation failed: ~p", [Reason]);
{ok, _} ->
Expand Down
7 changes: 5 additions & 2 deletions apps/rebar/src/rebar_prv_edoc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ do(State) ->
%% order of the merge is important to allow app opts overrides
AppEdocOpts = merge_opts(rebar_opts:get(AppOpts, edoc_opts, []), EdocOptsAcc),
?DEBUG("{edoc_opts, ~p}.", [AppEdocOpts]),
AppRes = (catch edoc:application(list_to_atom(AppName), AppDir, AppEdocOpts)),
AppRes =
try edoc:application(list_to_atom(AppName), AppDir, AppEdocOpts)
catch _:_ -> error
end,
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, AppInfo, State),
case {AppRes, ShouldAccPaths} of
{ok, true} ->
%% edoc wants / on all OSes
add_to_paths(EdocOptsAcc, AppDir++"/doc");
{ok, false} ->
EdocOptsAcc;
{{'EXIT', error}, _} ->
{error, _} ->
%% EDoc is not very descriptive
%% in terms of failures
throw({app_failed, AppName})
Expand Down
4 changes: 2 additions & 2 deletions apps/rebar/src/rebar_prv_shell.erl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ rewrite_leaders(OldUser, NewUser) ->
%% set any process that had a reference to the old user's group leader to the
%% new user process. Catch the race condition when the Pid exited after the
%% liveness check.
_ = [catch erlang:group_leader(NewUser, Pid)
_ = [try erlang:group_leader(NewUser, Pid) catch _:_ -> ok end
|| Pid <- erlang:processes(),
[_|_] = Info <- [erlang:process_info(Pid)],
proplists:get_value(group_leader, Info) == OldUser,
Expand All @@ -260,7 +260,7 @@ rewrite_leaders(OldUser, NewUser) ->
Pid < NewUser, % only change old masters
{_,Dict} <- [erlang:process_info(Pid, dictionary)],
{application_master,init,4} == proplists:get_value('$initial_call', Dict)],
_ = [catch erlang:group_leader(NewUser, Pid)
_ = [try erlang:group_leader(NewUser, Pid) catch _:_ -> ok end
|| Pid <- erlang:processes(),
lists:member(proplists:get_value(group_leader, erlang:process_info(Pid)),
OldMasters)],
Expand Down
70 changes: 48 additions & 22 deletions apps/rebar/src/rebar_user.erl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ catch_loop(Port, Shell) ->
catch_loop(Port, Shell, queue:new()).

catch_loop(Port, Shell, Q) ->
case catch server_loop(Port, Q) of
case catcher(fun() -> server_loop(Port, Q) end) of
new_shell ->
exit(Shell, kill),
catch_loop(Port, start_new_shell());
Expand Down Expand Up @@ -170,12 +170,15 @@ server_loop(Port, Q) ->


get_fd_geometry(Port) ->
case (catch port_control(Port,?CTRL_OP_GET_WINSIZE,[])) of
try port_control(Port,?CTRL_OP_GET_WINSIZE,[]) of
List when length(List) =:= 8 ->
<<W:32/native,H:32/native>> = list_to_binary(List),
{W,H};
_ ->
error
catch
_:_ ->
error
end.


Expand All @@ -201,7 +204,7 @@ io_request({put_chars,unicode,Chars}, Port, Q) -> % Binary new in R9C
put_chars(Bin, Port, Q)
end;
io_request({put_chars,unicode,Mod,Func,Args}, Port, Q) ->
case catch apply(Mod,Func,Args) of
case catcher(fun() -> apply(Mod,Func,Args) end) of
Data when is_list(Data); is_binary(Data) ->
case wrap_characters_to_binary(Data, unicode, get(encoding)) of
Bin when is_binary(Bin) ->
Expand All @@ -213,17 +216,17 @@ io_request({put_chars,unicode,Mod,Func,Args}, Port, Q) ->
put_chars(Undef, Port, Q)
end;
io_request({put_chars,latin1,Chars}, Port, Q) -> % Binary new in R9C
case catch unicode:characters_to_binary(Chars, latin1, get(encoding)) of
case wrap_unicode_characters_to_binary(Chars, latin1, get(encoding)) of
Data when is_binary(Data) ->
put_chars(Data, Port, Q);
_ ->
{error,{error,put_chars},Q}
end;
io_request({put_chars,latin1,Mod,Func,Args}, Port, Q) ->
case catch apply(Mod,Func,Args) of
case catcher(fun() -> apply(Mod,Func,Args) end) of
Data when is_list(Data); is_binary(Data) ->
case
catch unicode:characters_to_binary(Data,latin1,get(encoding))
wrap_unicode_characters_to_binary(Data,latin1,get(encoding))
of
Bin when is_binary(Bin) ->
put_chars(Bin, Port, Q);
Expand Down Expand Up @@ -317,10 +320,10 @@ put_chars(Chars, Port, Q) when is_binary(Chars) ->
ok = put_port(Chars, Port),
{ok,ok,Q};
put_chars(Chars, Port, Q) ->
case catch list_to_binary(Chars) of
Binary when is_binary(Binary) ->
put_chars(Binary, Port, Q);
_ ->
try list_to_binary(Chars) of
Binary ->
put_chars(Binary, Port, Q)
catch _:_ ->
{error,{error,put_chars},Q}
end.

Expand Down Expand Up @@ -603,7 +606,7 @@ get_chars_bytes(State, M, F, Xa, Port, Q, Bytes, Enc) ->
end.

get_chars_apply(State0, M, F, Xa, Port, Q, Enc) ->
case catch M:F(State0, cast(queue:head(Q),Enc), Enc, Xa) of
case catcher(fun() -> M:F(State0, cast(queue:head(Q),Enc), Enc, Xa) end) of
{stop,Result,<<>>} ->
{ok,Result,queue:tail(Q)};
{stop,Result,[]} ->
Expand Down Expand Up @@ -676,36 +679,36 @@ cast(Data, Encoding) ->
cast(B, binary, latin1, latin1) when is_binary(B) ->
B;
cast(L, binary, latin1, latin1) ->
case catch erlang:iolist_to_binary(L) of
case wrap_erlang_iolist_to_binary(L) of
Bin when is_binary(Bin) -> Bin;
_ -> exit({no_translation, latin1, latin1})
end;
cast(Data, binary, unicode, latin1) when is_binary(Data); is_list(Data) ->
case catch unicode:characters_to_binary(Data, unicode, latin1) of
case wrap_unicode_characters_to_binary(Data, unicode, latin1) of
Bin when is_binary(Bin) -> Bin;
_ -> exit({no_translation, unicode, latin1})
end;
cast(Data, binary, latin1, unicode) when is_binary(Data); is_list(Data) ->
case catch unicode:characters_to_binary(Data, latin1, unicode) of
case wrap_unicode_characters_to_binary(Data, latin1, unicode) of
Bin when is_binary(Bin) -> Bin;
_ -> exit({no_translation, latin1, unicode})
end;
cast(B, binary, unicode, unicode) when is_binary(B) ->
B;
cast(L, binary, unicode, unicode) ->
case catch unicode:characters_to_binary(L, unicode) of
case wrap_unicode_characters_to_binary(L, unicode, unicode) of
Bin when is_binary(Bin) -> Bin;
_ -> exit({no_translation, unicode, unicode})
end;
cast(B, list, latin1, latin1) when is_binary(B) ->
binary_to_list(B);
cast(L, list, latin1, latin1) ->
case catch erlang:iolist_to_binary(L) of
case wrap_erlang_iolist_to_binary(L) of
Bin when is_binary(Bin) -> binary_to_list(Bin);
_ -> exit({no_translation, latin1, latin1})
end;
cast(Data, list, unicode, latin1) when is_binary(Data); is_list(Data) ->
case catch unicode:characters_to_list(Data, unicode) of
case wrap_unicode_characters_to_list(Data, unicode) of
Chars when is_list(Chars) ->
[ case X of
High when High > 255 ->
Expand All @@ -717,22 +720,22 @@ cast(Data, list, unicode, latin1) when is_binary(Data); is_list(Data) ->
exit({no_translation, unicode, latin1})
end;
cast(Data, list, latin1, unicode) when is_binary(Data); is_list(Data) ->
case catch unicode:characters_to_list(Data, latin1) of
case wrap_unicode_characters_to_list(Data, latin1) of
Chars when is_list(Chars) -> Chars;
_ -> exit({no_translation, latin1, unicode})
end;
cast(Data, list, unicode, unicode) when is_binary(Data); is_list(Data) ->
case catch unicode:characters_to_list(Data, unicode) of
case wrap_unicode_characters_to_list(Data, unicode) of
Chars when is_list(Chars) -> Chars;
_ -> exit({no_translation, unicode, unicode})
end.

wrap_characters_to_binary(Chars, unicode, latin1) ->
case catch unicode:characters_to_binary(Chars, unicode, latin1) of
case wrap_unicode_characters_to_binary(Chars, unicode, latin1) of
Bin when is_binary(Bin) ->
Bin;
_ ->
case catch unicode:characters_to_list(Chars, unicode) of
case wrap_unicode_characters_to_list(Chars, unicode) of
L when is_list(L) ->
list_to_binary(
[ case X of
Expand All @@ -748,10 +751,33 @@ wrap_characters_to_binary(Chars, unicode, latin1) ->
wrap_characters_to_binary(Bin, From, From) when is_binary(Bin) ->
Bin;
wrap_characters_to_binary(Chars, From, To) ->
case catch unicode:characters_to_binary(Chars, From, To) of
case wrap_unicode_characters_to_binary(Chars, From, To) of
Bin when is_binary(Bin) ->
Bin;
_ ->
error
end.

wrap_erlang_iolist_to_binary(L) ->
try erlang:iolist_to_binary(L)
catch _:_ -> error
end.

wrap_unicode_characters_to_binary(Chars, InEncoding, OutEncoding) ->
try unicode:characters_to_binary(Chars, InEncoding, OutEncoding)
catch _:_ -> error
end.

wrap_unicode_characters_to_list(Chars, InEncoding) ->
try unicode:characters_to_list(Chars, InEncoding)
catch _:_ -> error
end.

%% This module has "interesting" control-flow, so where it's not obvious that
%% it's not needed, we use this emulation of old-style catches.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is vendored from the user module in Erlang/OTP. We'll need to grab a refreshed copy of it ideally, but this will do for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like rebar_user.erl is based on OTP-18's user.erl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTP's user.erl was deleted after OTP-25, so if you're looking for changes in the upcoming OTP-29 to eliminate old-style catches in it you won't find any.

catcher(Fun) ->
try Fun()
catch throw:Result -> Result;
error:Reason:ST -> {'EXIT', {Reason, ST}};
exit:Reason -> {'EXIT', Reason}
end.
2 changes: 1 addition & 1 deletion apps/rebar/test/mock_pkg_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ parse_deps(Deps) ->
requirement := Constraint} <- Deps].

to_index(AllDeps, Dict, Repos) ->
catch ets:delete(?PACKAGE_TABLE),
try ets:delete(?PACKAGE_TABLE) catch _:_ -> ok end,
rebar_packages:new_package_table(),

dict:fold(
Expand Down
7 changes: 4 additions & 3 deletions apps/rebar/test/rebar_compile_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ maybe_init_config(Config) ->
end.

end_per_testcase(_, _Config) ->
catch meck:unload().
try meck:unload() catch _:_ -> ok end.


%% test cases
Expand Down Expand Up @@ -1546,8 +1546,9 @@ umbrella_mib_first_test(Config) ->
PrivMibsDir = filename:join([AppsDir, "_build", "default", "lib", Name, "priv", "mibs"]),

FailureRebarConfig = [{mib_first_files, ["mibs/AIMPORTER-MIB.mib"]}],
catch (
rebar_test_utils:run_and_check(Config, FailureRebarConfig, ["compile"], {ok, [{app, Name}]}) ),
try
rebar_test_utils:run_and_check(Config, FailureRebarConfig, ["compile"], {ok, [{app, Name}]})
catch _:_ -> ok end,

%% check that the bin file was NOT created
false = filelib:is_file(filename:join([PrivMibsDir, "AIMPORTER-MIB.bin"])),
Expand Down
3 changes: 2 additions & 1 deletion apps/rebar/test/rebar_ct_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,8 @@ cfg_cover_spec(Config) ->
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),

RebarConfig = [{ct_opts, [Opt = {cover, "spec/foo.spec"}]}],
Opt = {cover, "spec/foo.spec"},
RebarConfig = [{ct_opts, [Opt]}],

{ok, State} = rebar_test_utils:run_and_check(C, RebarConfig, ["as", "test", "lock"], return),

Expand Down
2 changes: 1 addition & 1 deletion apps/rebar/test/rebar_hooks_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ init_per_testcase(_, Config) ->
rebar_test_utils:init_rebar_state(Config).

end_per_testcase(_, _Config) ->
catch meck:unload().
try meck:unload() catch _:_ -> ok end.

all() ->
[build_and_clean_app, run_hooks_once, run_hooks_once_profiles,
Expand Down
20 changes: 15 additions & 5 deletions apps/rebar/test/rebar_paths_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ check_modules(Config) ->
ct:pal("code:get_path() -> ~p", [code:get_path()]),

?assertEqual(RootDir ++ "_build/default/plugins/lib/rp_a/ebin", rp_a:f()),
ct:pal("~p", [catch file:list_dir(RootDir ++ "_build/default/lib/")]),
ct:pal("~p", [catch file:list_dir(RootDir ++ "_build/default/lib/rp_b/")]),
ct:pal("~p", [catch file:list_dir(RootDir ++ "_build/default/lib/rp_b/ebin")]),
ct:pal("~p", [catch b:module_info()]),
ct:pal("~p", [safe_list_dir(RootDir ++ "_build/default/lib/")]),
ct:pal("~p", [safe_list_dir(RootDir ++ "_build/default/lib/rp_b/")]),
ct:pal("~p", [safe_list_dir(RootDir ++ "_build/default/lib/rp_b/ebin")]),
ct:pal("~p", [safe_module_info(b)]),
?assertEqual(RootDir ++ "_build/default/lib/rp_b/ebin", rp_b:f()),
?assertEqual(RootDir ++ "_build/default/lib/rp_c/ebin", rp_c:f()),
?assertEqual(RootDir ++ "_build/default/lib/rp_d/ebin", rp_d:f()),
Expand Down Expand Up @@ -293,4 +293,14 @@ apps_to_str([]) ->
"stdlib, kernel";
apps_to_str(Apps) ->
AppsStr = unicode:characters_to_list(lists:join(", ", Apps)),
"stdlib, kernel, " ++ AppsStr.
"stdlib, kernel, " ++ AppsStr.

safe_list_dir(Path) ->
try file:list_dir(Path)
catch Class:Reason -> {Path, {Class, Reason}}
end.

safe_module_info(Mod) ->
try Mod:module_info()
catch Class:Reason -> {Mod, {Class, Reason}}
end.
4 changes: 2 additions & 2 deletions apps/rebar/test/rebar_pkg_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ mock_config(Name, Config) ->
filelib:ensure_dir(filename:join([CacheDir, "registry"])),
ok = ets:tab2file(Tid, filename:join([CacheDir, "registry"])),

catch ets:delete(?PACKAGE_TABLE),
try ets:delete(?PACKAGE_TABLE) catch _:_ -> ok end,
rebar_packages:new_package_table(),
lists:foreach(fun({{N, Vsn}, [Deps, InnerChecksum, OuterChecksum, _]}) ->
case ets:member(?PACKAGE_TABLE, {ec_cnv:to_binary(N), Vsn, <<"hexpm">>}) of
Expand Down Expand Up @@ -365,7 +365,7 @@ mock_config(Name, Config) ->

unmock_config(Config) ->
meck:unload(),
catch ets:delete(?config(mock_table, Config)).
try ets:delete(?config(mock_table, Config)) catch _:_ -> ok end.

copy_to_cache({Pkg,Vsn}, Config) ->
Name = <<Pkg/binary, "-", Vsn/binary, ".tar">>,
Expand Down
2 changes: 1 addition & 1 deletion apps/rebar/test/rebar_pkg_alias_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mock_config(Name, Config) ->
meck:new(rebar_prv_update, [passthrough]),
meck:expect(rebar_prv_update, do, fun(State) -> {ok, State} end),

catch ets:delete(?PACKAGE_TABLE),
try ets:delete(?PACKAGE_TABLE) catch _:_ -> ok end,
rebar_packages:new_package_table(),

lists:foreach(fun({{N, Vsn}, [Deps, Checksum, _]}) ->
Expand Down
2 changes: 1 addition & 1 deletion apps/rebar/test/rebar_pkg_repos_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ or_in_prerelease(Config) ->
%%

setup_deps_and_repos(Deps, Repos) ->
catch ets:delete(?PACKAGE_TABLE),
try ets:delete(?PACKAGE_TABLE) catch _:_ -> ok end,
true = rebar_packages:new_package_table(),
insert_deps(Deps),
State = rebar_state:new([{hex, [{repos, [#{name => R} || R <- Repos]}]}]),
Expand Down
6 changes: 3 additions & 3 deletions apps/rebar/test/rebar_plugins_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ init_per_testcase(_, Config) ->
rebar_test_utils:init_rebar_state(Config).

end_per_testcase(_, _Config) ->
catch meck:unload().
try meck:unload() catch _:_ -> ok end.

all() ->
[compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, upgrade_project_plugin,
Expand Down Expand Up @@ -212,7 +212,7 @@ upgrade(Config) ->
{ok, [{app, Name, valid}, {file, PluginBeam}, {plugin, PkgName, <<"0.1.1">>}]}
),

catch mock_pkg_resource:unmock(),
try mock_pkg_resource:unmock() catch _:_ -> ok end,
mock_pkg_resource:mock([
{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
{{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
Expand Down Expand Up @@ -256,7 +256,7 @@ upgrade_project_plugin(Config) ->
{ok, [{app, Name}, {plugin, PkgName, <<"0.1.1">>}]}
),

catch mock_pkg_resource:unmock(),
try mock_pkg_resource:unmock() catch _:_ -> ok end,
mock_pkg_resource:mock([
{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []},
{{iolist_to_binary(PkgName), <<"0.0.1">>}, []},
Expand Down
Loading
Loading