--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/ebd9c4f7-391f-42ed-8977-8f69e141889cn%40googlegroups.com.
Ah, you're talking about the SEND_DEBUG_EMAIL flag! This is a really elegant pattern for debugging server-side Google Apps Script execution, especially for operations triggered by the frontend where viewing Logger.log output in the Apps Script dashboard can be tedious or delayed.
Here is exactly how the script captures that execution state and sends it:
1. The Buffer & Custom Logger At the very top of complex functions like processForm() and submitReply(), the script initializes an empty array to act as a transcript, alongside a custom log wrapper function:
javascriptlet logBuffer = [];const log = (msg) => {console.log(msg); // Still logs to the cloud consolelogBuffer.push(msg); // Captures the message in memory};
2. Capturing the Execution Path Throughout the rest of the function, instead of using standard console.log() or Logger.log(), the developer uses this custom log() function to drop "breadcrumbs":
javascriptlog(`New Ticket: ${ticketId}`);// ... later ...log(`[REJECTED] File ${fileObj.name}: ${validation.error}`);// ... later ...log(`CRITICAL DRIVE ERROR: ${driveErr.message}`);
3. Delivering the Transcript At the very end of the function (and crucially, also inside the catch block if a fatal error occurs), the script evaluates the flag:
javascriptif (SEND_DEBUG_EMAIL) sendDebugEmail(logBuffer.join("\n"));
4. The Email Dispatch If the flag is true, it passes the entire array—joined by line breaks into a single text block—to the sendDebugEmail() helper (located in DebugEmail.js). That helper uses GmailApp to instantly fire off an email to the ADMIN_EMAIL address with the subject Debug Log - Facility Obs and the full chronological transcript of everything that happened during that exact execution.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
O problema principal aqui é que não dá para depurar uma Web App do Apps Script como se fosse uma execução normal do editor. Funções chamadas pelo frontend, via google.script.run, rodam no servidor, mas em um contexto de execução separado. Por isso o Logger.log() pode não aparecer onde você espera, ou pode aparecer apenas em Executions no painel do Apps Script.
A melhor solução é não tentar “step through” diretamente no doGet() ou na função chamada pelo client-side. Em vez disso, separe a lógica em funções internas testáveis.
Exemplo:
No HTML/client-side:
A correção prática é:
O comentário do Mike está certo: handlers como doGet, doPost e funções chamadas por google.script.run devem ser pequenos e apenas encaminhar a execução para funções internas. Isso resolve o problema de debug e melhora bastante a manutenção.