Troubleshooting Stay organized with collections Save and categorize content based on your preferences.
Even the most experienced developer rarely writes code correctly on the firsttry, making troubleshooting an important part of the development process. Inthis section we'll cover some techniques that can help you find, understand, anddebug errors in your scripts.
Error messages
When your script encounters an error, an error message is displayed. The messageis accompanied by a line number used for troubleshooting. There are two basictypes of errors displayed in this way:syntax errors andruntime errors.
Syntax errors
Syntax errors are caused by writing code that doesn't follow the JavaScriptgrammar, and the errors are detected as soon as you try to save the script.For example, the following code snippet contains a syntax error:
functionemailDataRow(rowNumber){varsheet=SpreadsheetApp.getActiveSheet();vardata=sheet.getDataRange().getValues();varrowData=data[rowNumber-1].join(" ";MailApp.sendEmail('john@example.com','Data in row '+rowNumber,rowData);}
The syntax problem here is a missing)
character at the end of the fourthline. When you try to save the script you'll get the following error:
Missing ) after argument list. (line 4)
These types of errors are usually simple to troubleshoot, since they are foundright away and typically have simple causes. You aren't able to save afile that contains syntax errors, meaning that only valid code is saved intoyour project.
Runtime errors
These errors are caused by using a function or class incorrectly, and can onlybe detected once the script has been run. For example, the following codecauses a runtime error:
functionemailDataRow(rowNumber){varsheet=SpreadsheetApp.getActiveSheet();vardata=sheet.getDataRange().getValues();varrowData=data[rowNumber-1].join(" ");MailApp.sendEmail('john','Data in row '+rowNumber,rowData);}
The code is formatted correctly, but we are passing the value "john" for theemail address when callingMailApp.sendEmail
. Since this is not avalid email address the following error is thrown when running the script:
Invalid email: john (line 5)
What makes these errors more challenging to troubleshoot is that often the datayou are passing into a function is not written in the code, but instead pulledfrom a spreadsheet, form, or other external data source. Using the debuggingtechniques below can help you to identify the cause of these errors.
Common errors
Below is a list of common errors and their causes.
Service invoked too many times: <action name>
This error indicates that you have exceeded your daily quota for a given action.For example, you might encounter this error if you send too many emails in asingle day. The quotas are set at different levels for consumer, domain, andpremier accounts and are subject to change at any time without a priorannouncement by Google. You can view the quota limits for various actions in theApps Script quota documentation.
Server not available. orServer error occurred, please try again.
There are a few possible causes for these errors:
- A Google server or system is temporarily unavailable. Wait for a few momentsand try running the script again.
- There is an error in your script that doesn't have a corresponding errormessage. Try debugging your script and see if you can isolate the problem.
- There is a bug in Google Apps Script that is causing this error. Forinstructions on searching for and filing bug reports, see theBugs. Before filing a new bug, searchto see if others have already reported it.
Authorization is required to perform that action.
This error indicates that the script is lacking the authorization needed to run.When a script is run in the Script Editor or from a custom menu item anauthorization dialog is presented to the user. However, when a script is runfrom a trigger, embedded with a Google Sites page, or run as a service, thedialog cannot be presented and this error is shown.
To authorize the script, open the Script Editor and run any function. Theauthorization prompt appears so you can authorize the script project. If thescript contains new unauthorized services, you must re-authorize the script.
This error is frequently caused bytriggers that are firing before theuser has authorized them. If you don't have access to the script project(because the error is occurring for anadd-on youuse, for example), you can usually authorize the script by using the add-onagain. If a trigger continues to fire and cause this error, you can remove yourtriggers by doing the following:
- At the left of the Apps Script project, clickTriggers .
- At the right of the trigger you want to remove, click More > Delete trigger.
You can also remove problematic add-on triggers byuninstalling the add-on.
Access denied: DriveApp orThe domain policy has disabled third-party Drive apps
Administrators of Google Workspace domains have theability to disable theDrive API for their domain, which prevents their users frominstalling and using Google Drive apps. This setting also prevents the usersfrom being able to use Apps Script add-ons that use theDrive service orAdvanced Drive Service(even if the script was authorized prior to the admin disabling Drive API).
However, if an add-on or web app using the Drive service is published fordomain-wide installationand is installed by the administrator for some or all users in the domain, thescript functions for those users even if the Drive API is disabled in thedomain.
The script does not have permission to get the active user's identity.
Indicates that the active user's identity and email are not available to thescript. This warning results from a call toSession.getActiveUser()
.It can also result from a call toSession.getEffectiveUser()
if the script is running in an authorization mode other thanAuthMode.FULL
.If this warning is signaled, subsequent calls toUser.getEmail()
only return "".
There are a number of ways to troubleshoot this warning, depending on theauthorization mode the script is running under. The authorization mode isexposed intriggered functions as theauthMode
property of thee
event parameter.
- In
AuthMode.FULL
, consider usingSession.getEffectiveUser()
instead. - In
AuthMode.LIMITED
, ensure thatthe owner has authorized the script. - In other authorization modes, avoid calling either method.
- If you are a Google Workspace customer newlyexperiencing this warning from aninstallable trigger, ensure thatthe trigger is running as a user within your organization.
Library is missing
If you add a popularlibrary to your script,you might receive an error messagestating that it's missing, even though the library is listed as a dependency foryour script. The reason might be that too many people are accessing the libraryat the same time. To avoid this error, try one of the following solutions:
- Copy and paste the library's code into your script and remove the librarydependency.
- Copy the library script and deploy it as a library from your account. Be sureto update the dependency in your original script to the new libraryinstead of the public one.
Error occurred due to a missing library version or a deployment version. Error code Not_Found
This error message indicates one of the following:
- The deployed version of the script has been deleted. To update the deployedversion of your script, seeEdit a versioneddeployment.
- The version of a library that the script uses has been deleted. To check whichlibrary is missing, next to the library name, click>Open in new tab. The missing librarygives an error message. After you find the library you need to update, takeone of the following actions:
- Update the library to use a different version. SeeUpdate alibrary.
- Remove the deleted library from your script project and code. SeeRemove a library.
More - The script of a library that your script uses includes anotherlibrary that uses a deleted version. Take one of the following actions:
- If you have edit access to the library that your script uses, update thesecondary library in that script to an existing version.
- Update the library to use a different version. SeeUpdate alibrary.
- Remove the library from your script project and code. SeeRemove a library.
Error 400: invalid_scope when calling Google Chat API with the advanced service
If you encounterError 400: invalid_scope
with the error messageSome requested scopes cannot be shown
,it means you haven't specified any authorization scopes in theApps Script project'sappsscript.json
file. In most cases,Apps Script automatically determines what scopes a script needs,but when you use the Chat advanced service, you must manually addthe authorization scopes that your script uses to yourApps Script project's manifest file. SeeSetting explicit scopes.
To resolve the error, add the appropriate authorization scopesto the Apps Script project'sappsscript.json
file as part oftheoauthScopes
array. For example, to call thespaces.messages.create
method, add the following:
"oauthScopes":["https://www.googleapis.com/auth/chat.messages.create"]
UrlFetch calls to <URL> are not permitted by your admin
Google Workspace administrators can turn on an allowlist in the admin consoleto control which external domains you can access throughApps Script.
To resolve the error, contact your administrator to have them add the URLto the allowlist.
Debugging
Not all mistakes cause an error message to be displayed. There might be a moresubtle error where the code is technically correct and can execute, but theresults are not what you expect. Here are some strategies for handling suchsituations and further investigating a script that is not running the way youexpect.
Logging
While debugging it's often helpful to record information as a script projectexecutes. Google Apps Script has two methods for logging information: theCloud logging serviceand the more basicLogger and console servicesthat are built in to the Apps Script editor.
See theLogging guide for more details.
Error Reporting
Note: To use Error Reporting in Google Cloud, your Apps Script project mustuse a standard, user-managed GCP project instead of the default,Apps Script-managed GCP project.Exceptions that occur because of runtime errors are automaticallyrecorded using the Google Cloud Error Reporting service. This service lets yousearch and filter exception messages your script project creates.
To access Error Reporting, seeView Cloud logs and error reports in the Google Cloud Platform console.
Executions
Every time you run a script, Apps Script makes a record of the execution, including the Cloud logs. These records can help you understand which actions your script performed.
To view the executions of your script in the Apps Script project, at the left, clickExecutions
.Checking Apps Script service status
Although rare, sometimes specific Google Workspaceservices (such as Gmail or Drive)encounter temporary problems that can lead to service outages. When thisoccurs, Apps Script projects that interact with these services may not functionas expected.
You can check if there is a Google Workspace serviceoutage by viewing theGoogle Workspace Status Dashboard.If an outage iscurrently being experienced, you either wait for it to be resolved or seekadditional help in theGoogle Workspace Help Centeror theGoogle Workspace Known Issuesdocumentation.
Use the debugger and breakpoints
To locate problems in your script, you can run it in debug mode. When run indebug mode, a script pauses when it hits a breakpoint, which is a line you'vehighlighted in your script that you think may have a problem. When a scriptpauses it displaysthe value of each variable at that point in time, allowing you to inspect theinner workings of a script without having to add a lot of logging statements.
Add a breakpoint
To add a breakpoint, hover over the line number of the line you want to add the breakpoint to. At the left of the line number, click the circle. The below image shows an example of a breakpoint added to a script:
Run a script in debug mode
To run the script in debug mode, at the top of the editor clickDebug.
Before the script runs the line with the breakpoint it pauses and displays a table of debug information. You can use this table to inspect data like the values of parameters and the information stored in objects.
To control how the script is run, at the top of the Debugger panel, use the "Step in", "Step over", and "Step out" buttons. These let you run the script one line at a time and inspect how values change over time.
Error: Source code for the current line is not available
This error appears when an active debugging file is not available.Google Apps Script does not support displaying dynamically generatedJavaScript (JS) scripts in the script editor, such as those generated usingeval()
andnew Function()
. These scripts are created and executedwithin the V8 engine but are not represented as standalone files in the editor.If you step-into these scripts, you will encounter this error.
For example, consider the following code:
functionmyFunction(){eval('a=2');}
Wheneval()
is invoked, its argument is treated as JS code and runs as adynamically created script inside the V8 engine. If you step-intoeval()
, thiserror appears. If the script includes a//# sourceURL
comment, its nameis shown in the call stack. Otherwise, it appears as an unnamed entry.
Despite the error message, the debugging session remains active, and executioncan continue. To proceed, continue to step in, step out or resumeexecution. However, this error continues to appear as long as the executionremains within the scope of the dynamic script. After execution moves out of thedynamic script, debugging continues without this error.
Issues with multiple Google Accounts
If you're logged into multiple Google Accounts at the same time, you mighthave trouble accessing your add-ons and web apps.Multi-login, orbeing logged into multiple Google Accounts at once, isn't supported for AppsScript, add-ons, or web apps.
If you open the Apps Script editor while logged in to more than one account,Google promptsyou to choose the account you want to proceed with.
If you open a web app or add-on and experience multi-login issues, try one ofthe following solutions:
- Log out of all your Google Accounts and only log in to the one that has theadd-on or web app you want to access.
- Open an incognito window in Google Chrome, or an equivalent private browsingwindow, and log in to the Google Account that has the add-on or web app youwant to access.
Getting help
Debugging a problem using the tools and techniques listed above can solve avariety of problems, but there may be issues you run into that require someextra help to solve. See ourSupport page forinformation on where to ask questions and file bugs.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-04 UTC.