fix: a file the hot folder touches mid-write, a folder away at start-up and a moment without network are warnings first (DTF-WEB-S, DTF-WEB-P, DTF-WEB-Q)
All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 7m42s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m57s
All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 7m42s
Build and deploy / Secret scan and release gate (push) Successful in 10s
Build and deploy / Publish images (push) Successful in 1m57s
- InvalidStateError (the FlexiPRINT's watcher changed a part while the browser wrote it) joins the files held by another program: the pass goes on and the next one tries again; it reaches Sentry if it lasts. - A NotFoundError with the main folder not answering (the server's share not up yet in the morning) says the folder is away and retries every 30 s; it reaches Sentry after 5 minutes. A file that vanished mid-pass keeps reporting at once, now in Portuguese. - A refresh that never reached the server (the computer waking up) says so and tries again; it reaches Sentry after 3 minutes offline. The folders' pass leaves that to the refresh. - "Liberar pasta" no longer creates the folders itself, where a failure was swallowed; the pass right after does it and reports. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -229,7 +229,10 @@ function freightWeight(fr){
|
|||||||
// A download button: the arrow, then its label.
|
// A download button: the arrow, then its label.
|
||||||
function downloadButton(text,fn,className){const b=button(text,fn,className);b.prepend(svgIcon(IC.download,'i m'));return b;}
|
function downloadButton(text,fn,className){const b=button(text,fn,className);b.prepend(svgIcon(IC.download,'i m'));return b;}
|
||||||
async function api(path,body){
|
async function api(path,body){
|
||||||
const r=await fetch('/api/operator'+path,{headers:{'Content-Type':'application/json'},...(body===undefined?{}:{method:'POST',body:JSON.stringify(body)})});
|
// A fetch that never reached the server (no network) is marked offline.
|
||||||
|
let r;
|
||||||
|
try{r=await fetch('/api/operator'+path,{headers:{'Content-Type':'application/json'},...(body===undefined?{}:{method:'POST',body:JSON.stringify(body)})});}
|
||||||
|
catch(e){e.offline=true;throw e;}
|
||||||
const d=await r.json();
|
const d=await r.json();
|
||||||
if(!r.ok){
|
if(!r.ok){
|
||||||
// A validation error is a list: name its first field and what was wrong
|
// A validation error is a list: name its first field and what was wrong
|
||||||
@@ -284,8 +287,11 @@ const FOLDER={mode:'showDirectoryPicker' in window?'folder':/Firefox\//.test(nav
|
|||||||
brave:!!navigator.brave,handle:null,granted:false,downloads:false,since:null,
|
brave:!!navigator.brave,handle:null,granted:false,downloads:false,since:null,
|
||||||
saved:new Map(),busy:false,status:'',error:'',last:null,lastSig:null,
|
saved:new Map(),busy:false,status:'',error:'',last:null,lastSig:null,
|
||||||
// Passes in a row each file was held open by another program (DTF-WEB-M).
|
// Passes in a row each file was held open by another program (DTF-WEB-M).
|
||||||
locked:new Map()};
|
locked:new Map(),
|
||||||
|
// Since when the main folder does not answer (DTF-WEB-P), and whether that was reported.
|
||||||
|
awaySince:0,awayReported:false};
|
||||||
const LOCKED_REPORT_PASSES=10;
|
const LOCKED_REPORT_PASSES=10;
|
||||||
|
const FOLDER_AWAY_REPORT_MS=5*60000;
|
||||||
// When the folders were chosen: every order paid since then ends up in them,
|
// When the folders were chosen: every order paid since then ends up in them,
|
||||||
// even one that went through while this computer was off (Dropstar's rules,
|
// even one that went through while this computer was off (Dropstar's rules,
|
||||||
// 2026-10-26). Folders chosen before this existed count from their first round.
|
// 2026-10-26). Folders chosen before this existed count from their first round.
|
||||||
@@ -410,7 +416,8 @@ function releaseFolder(){
|
|||||||
return folderReleasing||=(async()=>{
|
return folderReleasing||=(async()=>{
|
||||||
try{FOLDER.granted=(await FOLDER.handle.requestPermission({mode:'readwrite'}))==='granted';}
|
try{FOLDER.granted=(await FOLDER.handle.requestPermission({mode:'readwrite'}))==='granted';}
|
||||||
finally{folderReleasing=null;}
|
finally{folderReleasing=null;}
|
||||||
FOLDER.lastSig=null;FOLDER.error='';if(FOLDER.granted)await makeStageFolders();paintFolder();if(FOLDER.granted)syncFolder(true);
|
// The pass creates the flow's folders and says what failed, if anything.
|
||||||
|
FOLDER.lastSig=null;FOLDER.error='';paintFolder();if(FOLDER.granted)syncFolder(true);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
async function forgetFolder(){
|
async function forgetFolder(){
|
||||||
@@ -442,9 +449,11 @@ async function writeWhole(dir,name,source){
|
|||||||
await dir.removeEntry(temp.name);}
|
await dir.removeEntry(temp.name);}
|
||||||
}
|
}
|
||||||
// A file another program holds open (FlexiPRINT reading it, an editor): the
|
// A file another program holds open (FlexiPRINT reading it, an editor): the
|
||||||
// browser refuses to write, move or delete it. The pass goes on without it and
|
// browser refuses to write, move or delete it. One that program changed while
|
||||||
// the next one, 30 s later, tries again.
|
// the browser wrote or copied it (the hot folder's watcher, Sentry DTF-WEB-S)
|
||||||
const LOCKED=new Set(['NoModificationAllowedError','InvalidModificationError','NotReadableError']);
|
// is the same case. The pass goes on without it and the next one, 30 s later,
|
||||||
|
// tries again.
|
||||||
|
const LOCKED=new Set(['NoModificationAllowedError','InvalidModificationError','NotReadableError','InvalidStateError']);
|
||||||
function fileStep(locked){
|
function fileStep(locked){
|
||||||
return async(name,fn)=>{try{await fn();return true;}
|
return async(name,fn)=>{try{await fn();return true;}
|
||||||
catch(e){if(!LOCKED.has(e.name))throw e;locked.push(name);return false;}};
|
catch(e){if(!LOCKED.has(e.name))throw e;locked.push(name);return false;}};
|
||||||
@@ -452,6 +461,12 @@ function fileStep(locked){
|
|||||||
const stageDir=name=>FOLDER.handle.getDirectoryHandle(name,{create:true});
|
const stageDir=name=>FOLDER.handle.getDirectoryHandle(name,{create:true});
|
||||||
// The flow's folders exist from the moment the main one is chosen, empty or not.
|
// The flow's folders exist from the moment the main one is chosen, empty or not.
|
||||||
const makeStageFolders=()=>Promise.all([...new Set([...Object.values(STAGE_FOLDERS),PRINTING_FOLDER,RECEIPTS_FOLDER,REVIEWS_FOLDER])].map(stageDir));
|
const makeStageFolders=()=>Promise.all([...new Set([...Object.values(STAGE_FOLDERS),PRINTING_FOLDER,RECEIPTS_FOLDER,REVIEWS_FOLDER])].map(stageDir));
|
||||||
|
// Whether the main folder answers at all. A folder on the network can be away
|
||||||
|
// for a while: the server's share not up yet when the computer starts, the
|
||||||
|
// network down (Sentry DTF-WEB-P).
|
||||||
|
async function folderReachable(){
|
||||||
|
try{for await(const _ of FOLDER.handle.keys())break;return true;}catch{return false;}
|
||||||
|
}
|
||||||
// Remove a saved file from its folder; one already gone (someone took it) is fine.
|
// Remove a saved file from its folder; one already gone (someone took it) is fine.
|
||||||
async function removeSaved(rec){
|
async function removeSaved(rec){
|
||||||
const dir=await stageDir(rec.folder);
|
const dir=await stageDir(rec.folder);
|
||||||
@@ -604,7 +619,7 @@ async function syncFolder(force=false){
|
|||||||
FOLDER.saved.set(key,{order:review.order,name:review.name,review:true});
|
FOLDER.saved.set(key,{order:review.order,name:review.name,review:true});
|
||||||
FOLDER.last=new Date();await keepSaved();reviewSaved++;
|
FOLDER.last=new Date();await keepSaved();reviewSaved++;
|
||||||
}
|
}
|
||||||
FOLDER.lastSig=sig;FOLDER.error='';
|
FOLDER.lastSig=sig;FOLDER.error='';FOLDER.awaySince=0;FOLDER.awayReported=false;
|
||||||
FOLDER.status='';
|
FOLDER.status='';
|
||||||
if(saved)say((stages?'Salvos ':'Baixados ')+saved+' arquivo(s) em '+where+'.');
|
if(saved)say((stages?'Salvos ':'Baixados ')+saved+' arquivo(s) em '+where+'.');
|
||||||
if(hot)say('Gravados '+hot+' arquivo(s) na hot folder da máquina.');
|
if(hot)say('Gravados '+hot+' arquivo(s) na hot folder da máquina.');
|
||||||
@@ -621,7 +636,7 @@ async function syncFolder(force=false){
|
|||||||
if(locked.length){
|
if(locked.length){
|
||||||
FOLDER.lastSig=null;
|
FOLDER.lastSig=null;
|
||||||
FOLDER.error='O arquivo '+locked[0]+(locked.length>1?' e mais '+(locked.length-1):'')+
|
FOLDER.error='O arquivo '+locked[0]+(locked.length>1?' e mais '+(locked.length-1):'')+
|
||||||
' está aberto em outro programa (o FlexiPRINT, por exemplo). Os outros foram gravados; o Kanban tenta este de novo em 30 s.';
|
' está aberto ou foi mexido por outro programa (o FlexiPRINT, por exemplo). Os outros foram gravados; o Kanban tenta este de novo em 30 s.';
|
||||||
const stuck=locked.filter(name=>FOLDER.locked.get(name)===LOCKED_REPORT_PASSES);
|
const stuck=locked.filter(name=>FOLDER.locked.get(name)===LOCKED_REPORT_PASSES);
|
||||||
if(stuck.length)say('Pastas automáticas: o arquivo '+stuck.join(', ')+' segue aberto em outro programa há '+
|
if(stuck.length)say('Pastas automáticas: o arquivo '+stuck.join(', ')+' segue aberto em outro programa há '+
|
||||||
Math.round(LOCKED_REPORT_PASSES*30/60)+' minutos. Feche-o no programa que o usa.',true);
|
Math.round(LOCKED_REPORT_PASSES*30/60)+' minutos. Feche-o no programa que o usa.',true);
|
||||||
@@ -630,9 +645,25 @@ async function syncFolder(force=false){
|
|||||||
}catch(e){
|
}catch(e){
|
||||||
// The session ended (8 h) or the server is restarting: load() already shows
|
// The session ended (8 h) or the server is restarting: load() already shows
|
||||||
// the sign-in, and the folders resume after it (Sentry DTF-WEB-N).
|
// the sign-in, and the folders resume after it (Sentry DTF-WEB-N).
|
||||||
if(e.status===401||e.status===503){FOLDER.status='';return;}
|
// No network: load() says so, and reports it if it lasts (Sentry DTF-WEB-Q).
|
||||||
|
if(e.status===401||e.status===503||e.offline){FOLDER.status='';return;}
|
||||||
|
// The main folder away: a warning while it may come back by itself, an
|
||||||
|
// error (which reaches Sentry) after FOLDER_AWAY_REPORT_MS.
|
||||||
|
const name=FOLDER.handle?.name;
|
||||||
|
if(e.name==='NotFoundError'&&stages&&!await folderReachable()){
|
||||||
|
const first=!FOLDER.awaySince;FOLDER.awaySince||=Date.now();
|
||||||
|
FOLDER.status='';FOLDER.lastSig=null;
|
||||||
|
FOLDER.error='A pasta “'+name+'” não responde: a rede ou o servidor caiu, ou ela foi apagada. O Kanban tenta de novo a cada 30 s; se ela mudou de lugar, escolha a pasta de novo.';
|
||||||
|
if(!FOLDER.awayReported&&Date.now()-FOLDER.awaySince>=FOLDER_AWAY_REPORT_MS){
|
||||||
|
FOLDER.awayReported=true;
|
||||||
|
say('Pastas automáticas: a pasta “'+name+'” não responde há '+Math.round(FOLDER_AWAY_REPORT_MS/60000)+
|
||||||
|
' minutos. Confira a rede e o servidor, ou escolha a pasta de novo em Integrações.',true);
|
||||||
|
}else if(first)say('Pastas automáticas: '+FOLDER.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FOLDER.awaySince=0;FOLDER.awayReported=false;
|
||||||
if(e.name==='NotAllowedError')FOLDER.granted=false;
|
if(e.name==='NotAllowedError')FOLDER.granted=false;
|
||||||
else if(e.name==='NotFoundError')FOLDER.error='A pasta “'+FOLDER.handle?.name+'” não foi encontrada. Ela foi apagada ou a rede caiu? Escolha a pasta de novo.';
|
else if(e.name==='NotFoundError')FOLDER.error='Um arquivo ou pasta dentro de “'+name+'” sumiu durante a passagem (alguém tirou ou renomeou?). O Kanban tenta de novo sozinho.';
|
||||||
else FOLDER.error='A última tentativa falhou: '+e.message+' O Kanban tenta de novo sozinho.';
|
else FOLDER.error='A última tentativa falhou: '+e.message+' O Kanban tenta de novo sozinho.';
|
||||||
FOLDER.status='';say('Pastas automáticas: '+(FOLDER.error||'o navegador pediu para liberar a pasta de novo, em Integrações.'),true);
|
FOLDER.status='';say('Pastas automáticas: '+(FOLDER.error||'o navegador pediu para liberar a pasta de novo, em Integrações.'),true);
|
||||||
}finally{FOLDER.busy=false;paintFolder();}
|
}finally{FOLDER.busy=false;paintFolder();}
|
||||||
@@ -709,10 +740,15 @@ function itemPreview(item){
|
|||||||
|
|
||||||
// What the last load saw, so the next one can tell what is new.
|
// What the last load saw, so the next one can tell what is new.
|
||||||
let seenOrders=null, seenPending=null, unseen=0;
|
let seenOrders=null, seenPending=null, unseen=0;
|
||||||
|
// A network that drops for a moment (the computer waking up, the Wi-Fi) is
|
||||||
|
// not a bug: the next refresh tries again. Red, and so in Sentry, only when
|
||||||
|
// the server stays out of reach for OFFLINE_REPORT_MS (Sentry DTF-WEB-Q).
|
||||||
|
const OFFLINE_REPORT_MS=3*60000;
|
||||||
|
let offlineSince=0, offlineReported=false;
|
||||||
async function load(quiet=false){
|
async function load(quiet=false){
|
||||||
try{
|
try{
|
||||||
const [loaded,me]=await Promise.all([api('/board'),api('/me')]);
|
const [loaded,me]=await Promise.all([api('/board'),api('/me')]);
|
||||||
board=absorb(loaded);ME=me;
|
board=absorb(loaded);ME=me;offlineSince=0;offlineReported=false;
|
||||||
window.dtfEnvironment=me.sentry_environment||me.environment;
|
window.dtfEnvironment=me.sentry_environment||me.environment;
|
||||||
window.dtfRelease=me.sentry_release||undefined;
|
window.dtfRelease=me.sentry_release||undefined;
|
||||||
window.dtfObservability?.start?.(me.sentry_dsn_web,'kanban');
|
window.dtfObservability?.start?.(me.sentry_dsn_web,'kanban');
|
||||||
@@ -732,6 +768,14 @@ async function load(quiet=false){
|
|||||||
if(e.status===401||e.status===503){$('app').hidden=true;$('login').hidden=false;$('drawer').hidden=true;}
|
if(e.status===401||e.status===503){$('app').hidden=true;$('login').hidden=false;$('drawer').hidden=true;}
|
||||||
// Not being signed in yet is the normal start, not an error.
|
// Not being signed in yet is the normal start, not an error.
|
||||||
if(e.status===401){say('');return;}
|
if(e.status===401){say('');return;}
|
||||||
|
if(e.offline){
|
||||||
|
offlineSince||=Date.now();
|
||||||
|
if(!offlineReported&&Date.now()-offlineSince>=OFFLINE_REPORT_MS){
|
||||||
|
offlineReported=true;
|
||||||
|
say('Sem conexão com o servidor há '+Math.round(OFFLINE_REPORT_MS/60000)+' minutos. Confira a internet deste computador.',true);
|
||||||
|
}else say('Sem conexão com o servidor. O Kanban tenta de novo sozinho.',false,8000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
say(e.message,true);
|
say(e.message,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user