fix: a file the phone can no longer read says so in Portuguese and is picked again (DTF-WEB-2A)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m51s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 58s

Android Chrome threw NotReadableError reading a picked file (from Drive or
Photos, after switching apps); the customer saw the browser's English text
and "Tentar de novo", which reads the same dead file. The upload now says
"não conseguimos ler este arquivo no aparelho. Escolha o arquivo de novo",
the product page's button becomes "Escolher de novo" (the file leaves the
list and the picker opens), and the cart summary shows no retry for it.
upload_retry_test covers it and fails without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-12-01 18:05:46 -03:00
parent 961a72c0eb
commit cc0db89705
4 changed files with 55 additions and 9 deletions

View File

@@ -15,7 +15,19 @@ function releaseUploadSlot(){
async function sendUpload(file, {api, prefix='/uploads', startPath=prefix, progress=()=>{}, onBytes=()=>{}, scope='guest', resume=true, signal=null}) {
const cancelled=()=>new DOMException('Envio cancelado.','AbortError');
const samples=new Blob([file.slice(0,65536),file.slice(Math.max(0,file.size-65536))]);
const hash=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',await samples.arrayBuffer())),b=>b.toString(16).padStart(2,'0')).join('');
// A phone can lose the right to read a file it picked (Android: a file from
// Drive or Photos, after switching apps). The browser's message is English
// and a retry reads the same dead reference: picking the file again is the
// way out (Sentry DTF-WEB-2A).
let sampled;
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');
unreadable.unreadable=true;
throw unreadable;
}
const hash=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',sampled)),b=>b.toString(16).padStart(2,'0')).join('');
const key='dtf-upload:'+JSON.stringify([scope,file.name,file.size,file.lastModified,hash]);
// A busy server asks for a wait: retry this file alone, quietly, before the
// customer sees the failure (Marcus, 2026-11-11). Only a 429 that carries