Skip to content

Commit 5d35d7f

Browse files
committed
fix #3682
1 parent 49b128e commit 5d35d7f

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Fixes/improvements
22

3+
* [#3682] Add error handling to the `flash` OpenOS program
34
* [#3764] Fix left and right names being swapped in the Rack GUI
45
* [#3779] Fix `os.sleep(0)` causing `too long without yielding` (Ocawesome101)
56
* (1.12) [#3774] Fix Jukebox driver (kebufu)

src/main/resources/assets/opencomputers/loot/openos/bin/flash.lua

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ end
1515
local function printRom()
1616
local eeprom = component.eeprom
1717
io.write(eeprom.get())
18+
19+
return nil
1820
end
1921

2022
local function readRom()
@@ -37,6 +39,8 @@ local function readRom()
3739
if not options.q then
3840
io.write("All done!\nThe label is '" .. eeprom.getLabel() .. "'.\n")
3941
end
42+
43+
return nil
4044
end
4145

4246
local function writeRom()
@@ -60,15 +64,22 @@ local function writeRom()
6064
io.write("Please do NOT power down or restart your computer during this operation!\n")
6165
end
6266

63-
eeprom.set(bios)
67+
local result, reason = eeprom.set(bios)
68+
if reason then
69+
return nil, reason
70+
end
6471

6572
local label = args[2]
6673
if not options.q and not label then
6774
io.write("Enter new label for this EEPROM. Leave input blank to leave the label unchanged.\n")
6875
label = io.read()
6976
end
7077
if label and #label > 0 then
71-
eeprom.setLabel(label)
78+
local result, reason = eeprom.setLabel(label)
79+
if reason then
80+
return nil, reason
81+
end
82+
7283
if not options.q then
7384
io.write("Set label to '" .. eeprom.getLabel() .. "'.\n")
7485
end
@@ -77,12 +88,19 @@ local function writeRom()
7788
if not options.q then
7889
io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n")
7990
end
91+
92+
return nil
8093
end
8194

95+
local result, reason
8296
if options.l then
83-
printRom()
97+
result, reason = printRom()
8498
elseif options.r then
85-
readRom()
99+
result, reason = readRom()
86100
else
87-
writeRom()
101+
result, reason = writeRom()
88102
end
103+
if reason then
104+
io.stderr:write(reason..'\n')
105+
return 1
106+
end

src/main/scala/li/cil/oc/server/component/EEPROM.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class EEPROM extends prefab.ManagedEnvironment with DeviceInfo {
7676
return result(Unit, "storage is readonly")
7777
}
7878
label = args.optString(0, "EEPROM").trim.take(24)
79-
if (label.length == 0) label = "EEPROM"
79+
if (label.isEmpty) label = "EEPROM"
8080
result(label)
8181
}
8282

0 commit comments

Comments
 (0)