Use cases

Reviewed 2026-07-22

Google Apps Script のデバッグ

Apps Script の障害を安全に切り分けるための確認済みデバッグワークフローです。

A translucent spreadsheet grid, glass prism, and pencil on a dark work surface

How this page was reviewed

独立した Apps Script プロジェクトでテストしました。例ではデータや秘密をログに出さず、範囲を限定した診断を記録します。

01

安全な実装

最小の再現例を作り、機密でない診断を記録し、本番トリガーを変更する前にサービスとスコープを確認します。

02

失敗しやすい点

認可エラー、未定義値、サービスの割り当て量、トリガーコンテキストの違いはよくあります。ログを機密情報として扱い、修正後に一時的な診断を削除してください。

Implementation note

Tested example

function debugActiveSheet() {
  const sheet = SpreadsheetApp.getActiveSheet();
  if (!sheet) throw new Error('No active sheet');
  console.log(JSON.stringify({ name: sheet.getName(), rows: sheet.getLastRow() }));
}
Required scope
https://www.googleapis.com/auth/spreadsheets.currentonly
Expected output
実行ログにアクティブなシート名と最後に入力された行が記録されます。
Watch for
トリガーにはアクティブなスプレッドシートコンテキストがない場合があります。非バインドスクリプトでは明示的なスプレッドシート ID を渡してください。

Official sources

Read the original documentation before changing a production workflow.