how to catch exception and step name when failed

16 views
Skip to first unread message

SSync

unread,
Jun 29, 2018, 10:10:44 AM6/29/18
to bpipe-discuss
I would like to catch exception and failed step name in the pipeline - how can i do that?.

So, When a step in pipeline fails - i would like to capture exception in a variable and also take action accordingly. Moreover i want to capture name of the step failed.

Simon Sadedin

unread,
Jun 29, 2018, 11:03:38 PM6/29/18
to bpipe-discuss on behalf of SSync
There are a few different approaches to that.

If you want to do it generically, you can register an event listener:


bpipe.EventManager.instance.addListener(bpipe.PipelineEvent.STAGE_COMPLETED) { type, desc, details ->

    if(!details.stage.succeeded)
        println "Oh oh, received event of type $type: something failed:\n\n $desc\n\nThe details were:\n\n$details\n"

}

hello = {
    exec """
        echo "I'm such a failure"

        false
    """
}

run {
     hello
}


You can also use regular Java / Groovy exception handling if you only care about a particular stage:

hello = {
    try {
        exec """
            echo "I'm also a failure"

            false
        """
    }
    catch(Exception e) {
        println "Hmm, I caught a failure!"
        throw e
    }
}

run {
     hello + world
}

This second is a little bit more complex because Bpipe throws exceptions in some routine cases (for example, when you run "bpipe test", etc), so depending on your purpose you might need to avoid those. However it would also let you catch and choose not to rethrow the exception if you want to ignore the error and leave the pipeline running.

Cheers,

Simon


On Sat, Jun 30, 2018 at 12:10 AM, SSync via bpipe-discuss <bpipe-discuss+APn2wQcy85ckhFxW8t...@googlegroups.com> wrote:
I would like to catch exception and failed step name in the pipeline - how can i do that?.

So, When a step in pipeline fails - i would like to capture exception in a variable and also take action accordingly. Moreover i want to capture name of the step failed.

--
You received this message because you are subscribed to the Google Groups "bpipe-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bpipe-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to bpipe-...@googlegroups.com.
Visit this group at https://groups.google.com/group/bpipe-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages