Help

The Airtable Community will undergo scheduled maintenance on September 17 from 10:00 PM PST to 11:15 PM PST. During this period, you may experience temporary disruptions. We apologize for any inconvenience and appreciate your understanding.

Re: End a script early

1650 0
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.