Help

End a script early

Topic Labels: Scripting extentions
2552 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Matt_Caruso
6 - Interface Innovator
6 - Interface Innovator

Is it possible to end a script early? It seems like the process.exit() function isn’t available. I’d like to show an error message and exit if the input meets certain criteria.

1 Reply 1

I like to put the main functionality of a script inside a main function. If I want to end the script early, I use a return statement inside the script.

await main()
async function main() {
  // pseudo code for guard clause
  if (no data) {
    return;
  }
  // main script functionality
}

Almost all of my scripts have some sort of async call, so my main function almost always needs await/async. If your script doesn’t use any async calls, you can remove them.

This thread also has a discussion about using a “top-level” return, but it is not recommended.