What Causes the “INTERNAL Error” in Google Apps Script — and How to Fix It Reliably

* If you need help with the content of this article for work or development, individual support is available.

When working with Google Apps Script, you may encounter a vague and frustrating message:
“INTERNAL error.”
It gives no stack trace, no meaningful output, and no indication of where your code went wrong.

I’ve run into this issue myself when building LINE webhook automations and when working with slow external APIs through UrlFetchApp. Despite how mysterious the error seems, it follows a predictable set of causes.


◆ The real nature of INTERNAL errors

The key idea is: this error does not always result from your code.
In many cases, it happens because Google’s backend fails internally during execution.

Common triggers include:

  • API responses inside Google becoming unstable
  • Spreadsheets or Drive operations getting momentarily congested
  • Slow external API responses causing timeouts
  • Permission token inconsistencies
  • Concurrent triggers causing lock failures

In short, INTERNAL errors appear when GAS cannot complete its internal workflow.


◆ Common real-world scenarios

● 1. Slow external API via UrlFetchApp

This is the exact case that occurred in your environment.
When the external service responds too slowly, GAS may fail internally and throw the error.

Solution: Add retry logic.


● 2. Fragmented write operations

Calling setValue() repeatedly in loops overwhelms the backend.

Solution: Use setValues() to batch operations.


● 3. Concurrent triggers or doPost collisions

Multiple simultaneous executions may fight for locks, causing internal failures.

Solution: Always use LockService.


● 4. Missing or outdated permissions

After adding new APIs or swapping scripts, unrefreshed tokens can cause INTERNAL errors.

Solution: Run the script manually once and reauthorize.


● 5. Google-side outages

During backend disruptions, INTERNAL errors may become widespread.

Solution: Check Google Workspace Status.


◆ How to make your script stable

You cannot eliminate INTERNAL errors completely, but you can dramatically reduce them.

  • ✔ Add retry logic for external API calls
  • ✔ Batch all write operations
  • ✔ Use LockService to prevent conflicts
  • ✔ Refresh authorization when changing scopes
  • ✔ Break heavy processes into batches

These measures consistently reduce INTERNAL errors in real production scripts.

ZIDOOKA!

Need help with the content of this article?

I provide individual technical support related to the issues described in this article, as a freelance developer. If the problem is blocking your work or internal tasks, feel free to reach out.

Support starts from $30 USD (Estimate provided in advance)
Thank you for reading

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Policy on AI Usage

Some articles on this site are written with the assistance of AI. However, we do not rely entirely on AI for writing; it is used strictly as a support tool.