add more robust error handling for worker tasks

This commit is contained in:
Stewart Allen 2021-02-03 20:52:25 -05:00
commit 00d7ffec12
7 changed files with 98 additions and 69 deletions

View file

@ -62,11 +62,11 @@
* `B` clicking on a pop-op should pin it until clicked or [esc]
* `B` need to force cut line at synthetic z bottom (midlines, etc)
* `B` non-clear-voids duplicates thru-holes
* `B` failure to go *up* when moving between parts?
* `B` starting export during animation unleashes chaos
* `B` climb vs conventional not fully consistent after refactor
* `B` outside cutting direction in roughing mode inverted
* `F` import SVG into a path that can be overlaid onto a 3D mesh (laser?)
* `F` intelligently turn circle hole pocket clear into spiral down
* `F` trace follow hole that matches endmill should turn into a drill op
* `F` add climb/conventional into each operation

View file

@ -70,9 +70,9 @@ KIRI.work = {
worker.terminate();
}
for (let key in slicing) {
slicing[key]({error: "cancelled slicing"});
}
// for (let key in slicing) {
// slicing[key]({error: "cancelled slicing"});
// }
syncd = {};
slicing = {};
@ -188,6 +188,9 @@ KIRI.work = {
if (reply.done) {
done(reply.output, reply.maxSpeed);
}
if (reply.error) {
done(reply);
}
});
},
@ -199,6 +202,9 @@ KIRI.work = {
if (reply.done) {
ondone(reply.output);
}
if (reply.error) {
ondone(null, reply.error);
}
});
},

View file

@ -35,9 +35,11 @@
const gcode = [];
KIRI.client.export(API.conf.get(), (line) => {
gcode.push(line);
}, (output) => {
}, (output, error) => {
API.hide.alert(alert);
if (callback) {
if (error) {
API.show.alert(error, 5);
} else if (callback) {
callback(gcode.join('\r\n'), output);
} else {
exportGCodeDialog(gcode.join('\r\n'), output);
@ -48,8 +50,12 @@
function callExportLaser(options) {
KIRI.client.export(API.conf.get(), (line) => {
console.log({unexpected_line: line});
}, (output) => {
exportLaserDialog(output);
}, (output, error) => {
if (error) {
API.show.alert(error, 5);
} else {
exportLaserDialog(output);
}
});
}
@ -60,9 +66,13 @@
if (line.data) {
preview.push(line.data);
}
}, (output) => {
}, (output, error) => {
API.show.progress(0);
KIRI.driver.SLA.printDownload(preview, output, API);
if (error) {
API.show.alert(error, 5);
} else {
KIRI.driver.SLA.printDownload(preview, output, API);
}
});
}

View file

@ -898,9 +898,22 @@
}
API.event.emit('slice', getMode());
}
// handle slicing errors
if (error && !errored) {
errored = true;
setViewMode(VIEWS.ARRANGE);
alert2(error, 5);
API.show.progress(0);
KIRI.client.restart();
API.event.emit('slice.error', error);
}
// discard remaining errors
if (errored) {
return;
}
let alert = null;
// on the last exit, update ui and call the callback
if (--countdown === 0 || error || errored) {
if (--countdown === 0) {
if (scale === 1 && feature.work_alerts) {
alert = API.show.alert("Rendering");
};
@ -923,12 +936,13 @@
updateSliderMax(true);
setVisibleLayer(-1, 0);
});
// mark slicing complete for prep/preview
complete.slice = true;
if (scale === 1) {
API.show.progress(0);
}
// cause visuals to update
SPACE.scene.active();
// mark slicing complete for prep/preview
complete.slice = true;
API.event.emit('slice.end', getMode());
// print stats
segtimes.total = Date.now() - now;
@ -937,16 +951,6 @@
callback();
}
}
// handle slicing errors
if (error && !errored) {
API.show.progress(0);
API.hide.alert(alert);
errored = true;
setViewMode(VIEWS.ARRANGE);
setOpacity(color.model_opacity);
platform.deselect();
alert2(error, 1);
}
}, function(update, msg) {
if (msg && msg !== lastMsg) {
let mark = Date.now();
@ -1018,7 +1022,17 @@
startTime = mark;
}
API.show.progress(offset + progress * scale, message);
}, function (oldout, maxSpeed) {
}, function (reply, maxSpeed) {
// handle worker errors
if (reply && reply.error) {
alert2(reply.error, 5);
setViewMode(VIEWS.ARRANGE);
API.event.emit('preview.error', reply.error);
API.show.progress(0);
SPACE.update();
return;
}
if (lastMsg) {
segtimes[`${segNumber++}_${lastMsg}`] = Date.now() - startTime;
}

View file

@ -159,35 +159,30 @@ KIRI.worker = {
last = time(),
now;
try {
widget.slice(settings, function(error) {
if (error) {
send.data({error: error});
} else {
const slices = widget.slices || [];
send.data({send_start: time()});
send.data({
stats: widget.stats,
slices: slices.length,
});
slices.forEach(function(slice,index) {
const state = { zeros: [] };
send.data({index: index, slice: slice.encode(state)}, state.zeros);
})
send.data({send_end: time()});
}
send.done({done: true});
}, function(update, msg) {
now = time();
if (now - last < 10 && update < 0.99) return;
// on update
send.data({update: (0.05 + update * 0.95), updateStatus: msg});
last = now;
});
} catch (error) {
send.data({error: error.toString()});
console.log(error);
}
widget.slice(settings, function(error) {
if (error) {
send.data({error: error});
} else {
const slices = widget.slices || [];
send.data({send_start: time()});
send.data({
stats: widget.stats,
slices: slices.length,
});
slices.forEach(function(slice,index) {
const state = { zeros: [] };
send.data({index: index, slice: slice.encode(state)}, state.zeros);
})
send.data({send_end: time()});
}
send.done({done: true});
}, function(update, msg) {
now = time();
if (now - last < 10 && update < 0.99) return;
// on update
send.data({update: (0.05 + update * 0.95), updateStatus: msg});
last = now;
});
},
prepare: function(data, send) {
@ -593,20 +588,25 @@ self.onmessage = function(e) {
};
if (run) {
let time_xfer = (time_recv - msg.time),
output = run(msg.data, send),
time_send = time(),
time_proc = time_send - time_recv;
try {
let time_xfer = (time_recv - msg.time),
output = run(msg.data, send),
time_send = time(),
time_proc = time_send - time_recv;
if (output) self.postMessage({
seq: msg.seq,
task: msg.task,
time_send: time_xfer,
time_proc: time_proc,
// replaced on reply side
time_recv: time(),
data: output
});
if (output) self.postMessage({
seq: msg.seq,
task: msg.task,
time_send: time_xfer,
time_proc: time_proc,
// replaced on reply side
time_recv: time(),
data: output
});
} catch (wrkerr) {
console.log({wrkerr});
send.done({error: wrkerr.toString()});
}
} else {
console.log({kiri_msg:e});
}

View file

@ -20,7 +20,6 @@
*/
FDM.prepare = function(widgets, settings, update) {
settings = FDM.fixExtruders(settings);
let render = settings.render !== false,
{ device, process, controller, bounds, mode } = settings,
output = [],

View file

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="author" content="Stewart Allen">
<meta name="keywords" content="3d slicer,slicer,3d slicing,cnc,cam,toolpaths,toolpath generation,kiri,kirimoto,kiri:moto,gcode,cura,simplify 3d,prusaslicer,fdm,sla" />
<meta name="keywords" content="3d slicer,chromebook,slicer,3d slicing,cnc,cam,toolpaths,toolpath generation,kiri,kirimoto,kiri:moto,gcode,cura,simplify 3d,prusaslicer,fdm,sla" />
<meta name="copyright" content="stewart allen [sa@grid.space]">
<meta name="description" content="Browser-based 3D slicer, gcode and CNC toolpath generator">
<meta property="og:description" content="Kiri:Moto is a unique 3D slicer that runs entirely in browser and creates output for your favorite maker tools: 3D Printers, CNC Mills and Laser Cutters.">