From 035daa663b74f0297e539816a7bc262171f7597b Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:44:25 +0200 Subject: [PATCH] Berry `file.write()` raises an exception on failure (ex: disk full) (#21849) --- CHANGELOG.md | 1 + lib/libesp32/berry/src/be_filelib.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61d025f59..1332a0041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Berry `light.get` for separate RGB/CT (#21818) - Berry `bytes` setters and getters with negative offsets (#21835) +- Berry `file.write()` raises an exception on failure (ex: disk full) ### Removed - Berry internal: remove class from closure to simplify code (#21839) diff --git a/lib/libesp32/berry/src/be_filelib.c b/lib/libesp32/berry/src/be_filelib.c index f4f760b1e..5bd38bad8 100644 --- a/lib/libesp32/berry/src/be_filelib.c +++ b/lib/libesp32/berry/src/be_filelib.c @@ -26,7 +26,10 @@ static int i_write(bvm *vm) } else { data = be_tobytes(vm, 2, &size); } - be_fwrite(fh, data, size); + size_t bw = be_fwrite(fh, data, size); + if (bw != size) { + be_raise(vm, "io_error", "write failed"); + } } be_return_nil(vm); }