From fe5e9c4f4aad624d3403e21b7849915dd0e09690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 2 Dec 2026 14:23:11 -0300 Subject: [PATCH] fix: a file the phone cannot read tells the customer to save it on the phone first, and Sentry learns its kind (DTF-WEB-2D) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The same Android 10 phone failed three times on 2026-12-02 reading a file seven seconds after picking it: not a permission lost over time, but a file the phone does not have yet (Google Drive or WhatsApp). "Escolha o arquivo de novo" sent the customer back to the same file. The message now says "Se ele está no Google Drive ou no WhatsApp, salve no aparelho e escolha de novo". The Sentry notice carries the browser's error name, the file's type, extension and size in MB, never its name, so the next one says which case it is. Co-Authored-By: Claude Opus 5.5 --- tests/observability_web_test.mjs | 7 +++++++ tests/upload_retry_test.mjs | 5 ++++- web/checkout.js | 2 +- web/observability.js | 4 ++-- web/upload.js | 7 ++++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/observability_web_test.mjs b/tests/observability_web_test.mjs index e4932ae..85de21f 100644 --- a/tests/observability_web_test.mjs +++ b/tests/observability_web_test.mjs @@ -54,6 +54,13 @@ window.dtfObservability.uiError('Pastas automáticas: A última tentativa falhou assert.ok(captured, 'uiError sends a caught error'); assert.equal(captured.message, 'Aviso kanban: Pastas automáticas: A última tentativa falhou: :arquivo bloqueado.'); assert.deepEqual(captured.options.fingerprint, ['ui-error', 'kanban', 'Pastas automáticas: A última tentativa falhou: :arquivo bloqueado.']); +// Extra detail (the kind of file a phone could not read, DTF-WEB-2D) rides along. +captured = null; +window.dtfObservability.uiError('Envio de arquivo falhou: não conseguimos ler este arquivo no aparelho.', 'site', + {erro: 'NotReadableError', extensao: 'png', mb: 12.5}); +assert.equal(captured.options.extra.extensao, 'png'); +assert.equal(captured.options.extra.mb, 12.5); +assert.ok(captured.options.extra.page); apiError('/orders', 409, 'Falta a foto da revisão.'); captured = null; window.dtfObservability.uiError('Falta a foto da revisão.', 'kanban'); diff --git a/tests/upload_retry_test.mjs b/tests/upload_retry_test.mjs index d9d436e..7db393b 100644 --- a/tests/upload_retry_test.mjs +++ b/tests/upload_retry_test.mjs @@ -188,7 +188,10 @@ const run = async (completeSteps, {abortAfter} = {}) => { const {result, error, calls} = await run([{}]); assert.equal(result, undefined); assert.equal(error?.unreadable, true); - assert.match(error.message, /Escolha o arquivo de novo/); + assert.match(error.message, /salve no aparelho e escolha de novo/); + // Sentry learns the kind of file, never its name (DTF-WEB-2D). + assert.deepEqual(error.detalhe, {erro: 'NotReadableError', tipo: '', extensao: 'png', mb: 0}); + assert.ok(!JSON.stringify(error.detalhe).includes('a.png')); assert.equal(calls.length, 0, 'nothing reaches the server'); } finally { globalThis.Blob = RealBlob; diff --git a/web/checkout.js b/web/checkout.js index 28b25a5..40bf4c2 100644 --- a/web/checkout.js +++ b/web/checkout.js @@ -284,7 +284,7 @@ if(window.dtfContaAberta&&typeof pintaPedido==='function')pintaPedido();}, error=>{envios.delete(k);if(error?.name!=='AbortError'){falhas.set(k,{file,error}); // A refusal with a status already went to Sentry as an API error (DTF-WEB-15). - if(!error?.status)window.dtfObservability?.uiError?.('Envio de arquivo falhou: '+(error?.message||'erro no envio'),'site');}pintaEnvio();}); + if(!error?.status)window.dtfObservability?.uiError?.('Envio de arquivo falhou: '+(error?.message||'erro no envio'),'site',error?.detalhe);}pintaEnvio();}); envios.set(k,e); } return e.promise; diff --git a/web/observability.js b/web/observability.js index 07d5fe6..8eac7eb 100644 --- a/web/observability.js +++ b/web/observability.js @@ -149,14 +149,14 @@ // Every error the page shows the user in red, also the ones it caught and // handled itself (a folder it could not write, an upload that failed): the // team sees them in Sentry before anyone sends a screenshot. - function uiError(text, where) { + function uiError(text, where, detail) { if (!started || !text || typeof Sentry === 'undefined') return; const said = recent.get(String(text)); if (said && Date.now() - said < 15000) return; try { const kind = normalizedMessage(text); Sentry.captureMessage('Aviso ' + (where || app) + ': ' + kind, - {level: 'error', tags: {app, aviso: where || app}, extra: {page: location.pathname}, + {level: 'error', tags: {app, aviso: where || app}, extra: {page: location.pathname, ...(detail || {})}, fingerprint: ['ui-error', where || app, kind]}); } catch (error) { // Reporting an error must never break the page. diff --git a/web/upload.js b/web/upload.js index 81d19be..6ea27f8 100644 --- a/web/upload.js +++ b/web/upload.js @@ -23,8 +23,13 @@ async function sendUpload(file, {api, prefix='/uploads', startPath=prefix, progr try{ sampled=await samples.arrayBuffer(); } catch(error){ if(error?.name!=='NotReadableError' && error?.name!=='NotFoundError') throw error; - const unreadable=new Error('não conseguimos ler este arquivo no aparelho. Escolha o arquivo de novo'); + // A file in Google Drive or WhatsApp that is not on the phone yet fails the + // same way, at once (DTF-WEB-2D): the message says how to get out of it. + const unreadable=new Error('não conseguimos ler este arquivo no aparelho. Se ele está no Google Drive ou no WhatsApp, salve no aparelho e escolha de novo'); unreadable.unreadable=true; + // For Sentry: what kind of file the phone refused, never its name. + const ext=/\.([a-z0-9]{1,5})$/i.exec(file.name||'')?.[1]?.toLowerCase()||''; + unreadable.detalhe={erro:error.name,tipo:file.type||'',extensao:ext,mb:Math.round((file.size||0)/1048576*10)/10}; throw unreadable; } const hash=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',sampled)),b=>b.toString(16).padStart(2,'0')).join('');