Skip to content

Commit

Permalink
fix compatibility with R14
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Russ committed Jan 27, 2012
1 parent 77e2848 commit 0e80f07
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/tetrapak_task.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,33 @@ try_check(TaskModule, TaskName) ->
end
catch
error:Exn ->
case {Exn, erlang:get_stacktrace()} of
{undef, [{TaskModule, check, [TaskName], _Location} | _]} ->
%% check/1 is undefined, treat it as 'needs_run'
RightException =
case {Exn, erlang:get_stacktrace()} of
{undef, [LastFunction | _]} ->
check_exception(LastFunction, TaskModule, TaskName);
%% check/1 is undefined, treat it as 'needs_run'
{function_clause, [LastFunction | _]} ->
%% check/1 is defined, but not for this task, treat it as 'needs_run'
check_exception(LastFunction, TaskModule, TaskName);
_ ->
false
end,
case RightException of
true ->
{needs_run, undefined};
{function_clause, [{TaskModule, check, [TaskName], _Location} | _]} ->
%% check/1 is defined, but not for this task, treat it as 'needs_run'
{needs_run, undefined};
_ ->
false ->
handle_error(Function, error, Exn)
end;
Class:Exn ->
handle_error(Function, Class, Exn)
end.

% Compatible with R15
check_exception({TaskModule, check, [TaskName], _Location}, TaskModule, TaskName) -> true;
% Compatible with R14
check_exception({TaskModule, check, [TaskName]}, TaskModule, TaskName) -> true;
check_exception(_LastTrace, _TaskModule, _TaskName) -> false.

try_run(TaskModule, TaskName, TaskData) ->
Function = tpk_util:f("~s:run/1", [TaskModule]),
try
Expand Down

0 comments on commit 0e80f07

Please sign in to comment.