diff mbox series

[2/9] bitbake-setup: always restore sys.stdout

Message ID 20260322193440.870120-3-adrian.freihofer@siemens.com
State New
Headers show
Series bitbake-setup: improvements, VSCode workspace generation | expand

Commit Message

AdrianF March 22, 2026, 7:34 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

While working on the bitbake-setup update with a non destructive fetcher,
I noticed that if the fetcher raises an exception, sys.stdout is not
restored, which can lead to issues in the rest of the code. This change
ensures that sys.stdout is always restored, even if an exception occurs
during the fetch and unpack process.

Showing the full Traceback of the error would be a bit confusing because
it happened in code which is not yet ready for review, but the final
error was:
  ValueError: I/O operation on closed file.

and this little change seems to be a reasonable improvement to avoid
such issues.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 bin/bitbake-setup | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index dcad9c169..e8d520687 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -793,9 +793,11 @@  def do_fetch(fetcher, dir):
     with open(fetchlog, 'a') as f:
         oldstdout = sys.stdout
         sys.stdout = f
-        fetcher.download()
-        fetcher.unpack_update(dir)
-        sys.stdout = oldstdout
+        try:
+            fetcher.download()
+            fetcher.unpack_update(dir)
+        finally:
+            sys.stdout = oldstdout
 
 def update_registry(registry, cachedir, d):
     registrydir = 'configurations'