Skip to content

Commit e80f0a7

Browse files
microbit-sammicrobit-carlos
authored andcommitted
WebUSB: Filesystem error is not presented as a WebUSB error (#291)
1 parent 593d61e commit e80f0a7

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

python-main.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ function web_editor(config) {
14751475

14761476
function doFlash() {
14771477
var startTime = new Date().getTime();
1478-
1478+
14791479
// Hide serial and disconnect if open
14801480
if ($("#repl").css('display') != 'none') {
14811481
$("#repl").hide();
@@ -1495,7 +1495,12 @@ function web_editor(config) {
14951495
}
14961496
}
14971497

1498-
var p = Promise.resolve();
1498+
// Get the hex to flash in bytes format, exit if there is an error
1499+
try {
1500+
var output = generateFullHex('bytes');
1501+
} catch(e) {
1502+
return alert(config.translate.alerts.error + e.message);
1503+
}
14991504

15001505
$("#webusb-flashing-progress").val(0).hide();
15011506
$("#webusb-flashing-complete").hide();
@@ -1504,6 +1509,7 @@ function web_editor(config) {
15041509
$("#flashing-info").removeClass('hidden');
15051510
$("#flashing-overlay-container").css("display", "flex");
15061511

1512+
var p = Promise.resolve();
15071513
if (usePartialFlashing) {
15081514
REPL = null;
15091515
$("#repl").empty();
@@ -1513,15 +1519,13 @@ function web_editor(config) {
15131519
return PartialFlashing.connectDapAsync();
15141520
})
15151521
.then(function() {
1516-
var output = generateFullHex("bytes");
15171522
var updateProgress = function(progress) {
15181523
$("#webusb-flashing-progress").val(progress).css("display", "inline-block");
15191524
}
15201525
$("#webusb-flashing-loader").hide();
15211526
$("#webusb-flashing-progress").val(0).css("display", "inline-block");
15221527
return PartialFlashing.flashAsync(window.dapwrapper, output, updateProgress);
1523-
})
1524-
1528+
});
15251529
}
15261530
else {
15271531
// Push binary to board
@@ -1533,12 +1537,10 @@ function web_editor(config) {
15331537
$("#webusb-flashing-progress").val(progress).css("display", "inline-block");
15341538
});
15351539

1536-
var output = generateFullHex("string");
1537-
15381540
// Encode firmware for flashing
15391541
var enc = new TextEncoder();
15401542
var image = enc.encode(output).buffer;
1541-
1543+
15421544
$("#webusb-flashing-loader").hide();
15431545
$("#webusb-flashing-progress").val(0).css("display", "inline-block");
15441546
return window.daplink.flash(image);
@@ -1566,7 +1568,6 @@ function web_editor(config) {
15661568
.finally(function() {
15671569
// Remove event listener
15681570
window.removeEventListener("unhandledrejection", webusbErrorHandler);
1569-
15701571
});
15711572
}
15721573

0 commit comments

Comments
 (0)