/** * Wrap the provided task in a wrapper that will ignore * any errors or exceptions that may be produced. This * is useful, for example, in adding optional cleanup tasks * at the beginning of a task collection, to remove previous * results which may or may not exist. * * TODO: Provide some way to specify which sort of errors * are ignored, so that 'file not found' may be ignored, * but 'permission denied' reported? * * @param \Robo\Contract\TaskInterface $task * * @return \Robo\Collection\CallableTask */ public function ignoreErrorsTaskWrapper(TaskInterface $task) { // If the task is a stack-based task, then tell it // to try to run all of its operations, even if some // of them fail. if ($task instanceof StackBasedTask) { $task->stopOnFail(false); } $ignoreErrorsInTask = function () use($task) { $data = []; try { $result = $this->runSubtask($task); $message = $result->getMessage(); $data = $result->getData(); $data['exitcode'] = $result->getExitCode(); } catch (\Exception $e) { $message = $e->getMessage(); } return Result::success($task, $message, $data); }; // Wrap our ignore errors callable in a task. return new CallableTask($ignoreErrorsInTask, $this); }