From 5d35d7f9e1bb46dd1e22befc97a44faa2397e9c1 Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Sun, 1 Jun 2025 19:46:48 +0200 Subject: [PATCH] fix #3682 --- changelog.md | 1 + .../opencomputers/loot/openos/bin/flash.lua | 28 +++++++++++++++---- .../li/cil/oc/server/component/EEPROM.scala | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 642dfd8e3..bc595dcce 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ ## Fixes/improvements +* [#3682] Add error handling to the `flash` OpenOS program * [#3764] Fix left and right names being swapped in the Rack GUI * [#3779] Fix `os.sleep(0)` causing `too long without yielding` (Ocawesome101) * (1.12) [#3774] Fix Jukebox driver (kebufu) diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/flash.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/flash.lua index f8ecf4762..13e080e15 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/flash.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/flash.lua @@ -15,6 +15,8 @@ end local function printRom() local eeprom = component.eeprom io.write(eeprom.get()) + + return nil end local function readRom() @@ -37,6 +39,8 @@ local function readRom() if not options.q then io.write("All done!\nThe label is '" .. eeprom.getLabel() .. "'.\n") end + + return nil end local function writeRom() @@ -60,7 +64,10 @@ local function writeRom() io.write("Please do NOT power down or restart your computer during this operation!\n") end - eeprom.set(bios) + local result, reason = eeprom.set(bios) + if reason then + return nil, reason + end local label = args[2] if not options.q and not label then @@ -68,7 +75,11 @@ local function writeRom() label = io.read() end if label and #label > 0 then - eeprom.setLabel(label) + local result, reason = eeprom.setLabel(label) + if reason then + return nil, reason + end + if not options.q then io.write("Set label to '" .. eeprom.getLabel() .. "'.\n") end @@ -77,12 +88,19 @@ local function writeRom() if not options.q then io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n") end + + return nil end +local result, reason if options.l then - printRom() + result, reason = printRom() elseif options.r then - readRom() + result, reason = readRom() else - writeRom() + result, reason = writeRom() end +if reason then + io.stderr:write(reason..'\n') + return 1 +end \ No newline at end of file diff --git a/src/main/scala/li/cil/oc/server/component/EEPROM.scala b/src/main/scala/li/cil/oc/server/component/EEPROM.scala index cc907aff6..59143cb21 100644 --- a/src/main/scala/li/cil/oc/server/component/EEPROM.scala +++ b/src/main/scala/li/cil/oc/server/component/EEPROM.scala @@ -76,7 +76,7 @@ class EEPROM extends prefab.ManagedEnvironment with DeviceInfo { return result(Unit, "storage is readonly") } label = args.optString(0, "EEPROM").trim.take(24) - if (label.length == 0) label = "EEPROM" + if (label.isEmpty) label = "EEPROM" result(label) }