Skip to content

Conversation

@reziamini
Copy link
Contributor

Now, we are not able to do some stuff with the pipeline if there is a failed pipe.

With this new method, we will be able to throw a custom exception or our custom functionality (like logging, ...)

@reziamini reziamini force-pushed the pipeline_on_failure branch from c4de8fb to f3503c5 Compare June 2, 2022 16:20
return $this->handleCarry($carry);
} catch (Throwable $e) {
if ($this->onFailure) {
return call_user_func($this->onFailure, $pipe);
Copy link
Contributor

@rodrigopedra rodrigopedra Jun 2, 2022

Choose a reason for hiding this comment

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

It would be nice to also send the exception to the onFailure method, for logging purposes, for example.

I'd also suggest to send it as the first parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have any opinion on that, let's see what will Taylor say.

Copy link
Contributor

@michael-rubel michael-rubel Jun 2, 2022

Choose a reason for hiding this comment

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

@rezaamini-ir is usage of call_user_func() over $callable() still makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@michael-rubel Didn't get it, what's wrong with call_user_func?
Could you please be more specific?

Copy link
Contributor

@michael-rubel michael-rubel Jun 9, 2022

Choose a reason for hiding this comment

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

@rezaamini-ir I meant using of more modern approach ($this->onFailure)($pipe) instead of call_user_func($this->onFailure, $pipe).
Look at this line: https://github.com/michael-rubel/laravel-enhanced-pipeline/blob/main/src/Pipeline.php#L236

@taylorotwell
Copy link
Member

But you can do some stuff is there is a failed pipe using normal PHP try / catch syntax?

    try {
        $pipeline = (new Pipeline)->send('data')->through([
            fn () => throw new Exception('foo'),
        ])->then(fn ($piped) => $piped);
    } catch (Exception $e) {
        dd('here');
    }

@reziamini reziamini deleted the pipeline_on_failure branch June 6, 2022 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants