From 39cfd01361e7b0ff8c997c75100b97c5183b3bd6 Mon Sep 17 00:00:00 2001 From: makermelissa-ai-assistant <276182804+makermelissa-ai-assistant@users.noreply.github.com> Date: Tue, 1 Dec 2026 13:20:13 -0800 Subject: [PATCH] Report read-only BLE saves without retrying --- js/common/ble-file-transfer.js | 22 ++++++++++------------ js/script.js | 18 +++++++++++------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/js/common/ble-file-transfer.js b/js/common/ble-file-transfer.js index 2b24257..bc51df2 100644 --- a/js/common/ble-file-transfer.js +++ b/js/common/ble-file-transfer.js @@ -146,6 +146,14 @@ class FileTransferClient extends BLEFileTransferClient { this._signalMutatingOp(); } result = await operation(); + } catch (error) { + // The BLE library rejects with a string for STATUS_ERROR_READONLY. + if (mutating && error === "Filesystem is read-only") { + const writeProtectedError = new Error(error); + writeProtectedError.writeProtected = true; + throw writeProtectedError; + } + throw error; } finally { this._fileRequestInProgress = false; } @@ -180,19 +188,9 @@ class FileTransferClient extends BLEFileTransferClient { } async readOnly() { - let readonly = false; + // The BLE protocol reports read-only status on a file operation. + // Keep writes available so users can save once they release the drive. return false; - // Check if the device is read only - console.log("Checking if device is read only"); - // Attempt to write a 0-byte temp file and remove it - const testPath = '/._ble_readonly_check'; - try { - await this.writeFile(testPath, 0, new Uint8Array(0)); - await this.deleteFile(testPath); - } catch (e) { - readonly = true; - } - return readonly; } async versionInfo() { diff --git a/js/script.js b/js/script.js index f26c526..70071c7 100644 --- a/js/script.js +++ b/js/script.js @@ -1240,15 +1240,19 @@ async function saveFileContents(path, savingWorkflow, selection) { return false; } offset = 0; - // If the device cleanly told us the filesystem is held by - // someone else (most commonly USB-MSC: the host has - // CIRCUITPY mounted), retrying won't help -- surface an - // actionable hint immediately and bail. Older CircuitPython - // firmware returns 500 for this case, newer firmware - // returns 409 Conflict; web-file-transfer.js tags both - // with `writeProtected` so we can treat them the same way. + // BLE and web file transfers tag explicit read-only + // responses so saves can stop without retrying. if (e && e.writeProtected) { setSaved(false); + if (savingWorkflow.type === CONNTYPE.Ble) { + await showMessage( + "The board's filesystem is read-only over Bluetooth. " + + "If USB storage is holding it, eject CIRCUITPY and disconnect USB data " + + "while keeping the board powered, or disable USB Mass Storage in boot.py and reset the board. " + + "Your edits are still here. Save again once the filesystem is writable." + ); + return false; + } const learnUrl = e.helpUrl || "https://learn.adafruit.com/getting-started-with-web-workflow-using-the-code-editor/device-setup#disabling-usb-mass-storage-3125964"; const learnLabel = e.helpLabel || "Disabling USB Mass Storage (Adafruit Learn)"; // MessageModal renders via innerHTML, so real markup