Skip to content

py/moderrno: Add EBUSY to the default errno list. - #19737

Open
kwagyeman wants to merge 2 commits into
micropython:masterfrom
kwagyeman:kwabena/errno_ebusy
Open

kwagyeman wants to merge 2 commits into
micropython:masterfrom
kwagyeman:kwabena/errno_ebusy

Conversation

@kwagyeman

Copy link
Copy Markdown
Contributor

Summary

Adds EBUSY to the default MICROPY_PY_ERRNO_LIST, so errno.EBUSY exists and OSError(EBUSY) prints as [Errno 16] EBUSY instead of a bare number. Came up in #19617.

EBUSY is raised in 13 places across 10 files (extmod/btstack, extmod/nimble, extmod/machine_usb_device, extmod/vfs_fat_file, and the nrf, renesas-ra, rp2, samd and stm32 ports). That is more than most codes already in the list:

code uses files
EBUSY 13 10
EALREADY 12 5
EBADF 8 2
EINPROGRESS 7 4
ENOBUFS 4 2
ECONNRESET 4 1
EHOSTUNREACH 3 1
ECONNABORTED 3 1
EADDRINUSE 3 1
EISDIR 2 2
EEXIST 2 2
EACCES 1 1
ECONNREFUSED 0 0

Counted as MP_Exxx occurrences in *.c/*.h outside py/mperrno.h, py/moderrno.c and lib/.

Testing

basics/errno1.py passes on the unix port. str(OSError(errno.EBUSY)) gives [Errno 16] EBUSY. Code size: +56 bytes on an stm32 build.

Trade-offs and Alternatives

+56 bytes of flash on every port with the errno module, for a string on an error that currently prints as [Errno 16].

@kwagyeman

Copy link
Copy Markdown
Contributor Author

@dpgeorge

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Code size report:

Reference:  extmod: Remove support for mbedTLS <3.0. [19e685e]
Comparison: py/moderrno: Remove ECONNREFUSED from the default errno list. [merge of cc5ca2e]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    -8 -0.002% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    -8 -0.002% TEENSY40
        rp2:    -8 -0.001% RPI_PICO_W
       samd:    -8 -0.003% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    -8 -0.002% VIRT_RV32

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.59%. Comparing base (19e685e) to head (cc5ca2e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19737      +/-   ##
==========================================
+ Coverage   98.55%   98.59%   +0.03%     
==========================================
  Files         182      182              
  Lines       23342    23342              
  Branches        5        5              
==========================================
+ Hits        23005    23013       +8     
+ Misses        336      328       -8     
  Partials        1        1              
Flag Coverage Δ
unix-coverage-32bit 98.59% <ø> (+0.03%) ⬆️
unix-coverage-64bit 98.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Oct 1, 2026
@dpgeorge

dpgeorge commented Oct 1, 2026

Copy link
Copy Markdown
Member

Thanks for the analysis. How about we remove ECONNREFUSED from the list to get back the bytes? That's never used anywhere.

Also please update tests/cpydiff/types_oserror_errnomap.py.

EBUSY is raised in 13 places across 10 files (extmod/btstack,
extmod/nimble, extmod/machine_usb_device, extmod/vfs_fat_file, and the
nrf, renesas-ra, rp2, samd and stm32 ports), which is more than most of
the codes already in the list: EALREADY 12, EBADF 8, EINPROGRESS 7,
ENOBUFS 4, ECONNRESET 4, EHOSTUNREACH 3, ECONNABORTED 3, EADDRINUSE 3,
EISDIR 2, EEXIST 2, EACCES 1, ECONNREFUSED 0.  Without it the exception
prints as a bare "[Errno 16]" and errno.EBUSY does not exist.

Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
MP_ECONNREFUSED is not raised anywhere in the code base, so remove it from
the default list to recover the code size added by EBUSY.

Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
@kwagyeman
kwagyeman force-pushed the kwabena/errno_ebusy branch from f570cca to cc5ca2e Compare October 1, 2026 22:47
@kwagyeman

Copy link
Copy Markdown
Contributor Author

@dpgeorge Done

@dpgeorge dpgeorge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants