Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered
Salutations!
If a condition in a spark notebook is fulfilled (details not important), I want to exit the run (like with mssparkutils.notebook.exit("peekaboo!") ). I also want the pipeline which executes this notebook via the notebook activity to register this run as failed, just like if it had incidentally done so, not on purpose. How do I do that? Is it a specific exit value? Do I have to throw an exception, and if so, how would I go about that?
I mean, I could put some impossible code into the notebook, but there has to be a better way, right?
Thanks for your help!
Solved! Go to Solution.
@Anonymous - Ok. Then you will not be able to use .exit() but you can raise an exception to exit the Notebook. You can pass a message back via the exception to perform additional steps if needed.
if var == None: raise Exception("No match found.") else: var2 = var
@Anonymous - Pass your error code/text in the .exit() message. Then read that output into a variable or IF condition in the data pipeline and if the failure condition is true use the Fail Activity to stop the pipeline.
You can return a JSON string from the Notebook to the Pipeline, parse it in the pipeline so you can refer to an Error Code # and Message easier than just a standard string.
That is not what I want. I want the notebook activity itself to fail.
@Anonymous - Ok. Then you will not be able to use .exit() but you can raise an exception to exit the Notebook. You can pass a message back via the exception to perform additional steps if needed.
if var == None: raise Exception("No match found.") else: var2 = var
Hi, @Anonymous
You can use a Fail activity in a pipeline and customize both its error message and error code.
Please refer to the following documents for detailed information:
Fail activity - Microsoft Fabric | Microsoft Learn
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Fabric update to learn about new features.