From 520bcc2cdd4edab31ad031d227fd278de2fd3e59 Mon Sep 17 00:00:00 2001
From: moon2 <moon2protonmail@protonmail.com>
Date: Sun, 26 May 2024 22:38:22 +0200
Subject: [PATCH] updat3r: don't crash when sd breaks mid-transit

---
 python_payload/apps/updat3r/__init__.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/python_payload/apps/updat3r/__init__.py b/python_payload/apps/updat3r/__init__.py
index cb60e00499..1f3a317598 100644
--- a/python_payload/apps/updat3r/__init__.py
+++ b/python_payload/apps/updat3r/__init__.py
@@ -129,6 +129,9 @@ class UpdaterApp(Application):
                 yield path_fd.tell(), total_size
                 if len(new_data) < block_size:
                     break
+        except OSError as e:
+            if "EIO" in str(e):
+                self._sd_failed = True
         finally:
             path_fd.close()
             req.close()
@@ -183,7 +186,11 @@ class UpdaterApp(Application):
             return
 
         if self._sd_failed:
-            self._state_text = "don't panic, but...\na weird SD bug happened D:\nturn off and on flow3r power (ha)\nthen try to reattempt\ndownloading the update\n\nyou got this."
+            self._state_text = (
+                "don't panic, but...\na weird SD bug happened D:\nturn off and on flow3r power (ha)\n"
+                "and retry. some SD cards don't\nwork for this at all tho :/\n\n"
+                "if this error repeats try\nhttps://flow3r.garden/flasher\ninstead!"
+            )
             return
 
         if not st3m.wifi.is_connected() and not st3m.wifi.is_connecting():
-- 
GitLab