cibuildwheel icon indicating copy to clipboard operation
cibuildwheel copied to clipboard

Refactor error handling to use exceptions

Open joerick opened this issue 1 year ago • 1 comments

cibuildwheel has up until now handled most errors by printing an error message to sys.stderr and calling sys.exit. Others were handled using Logger.error, depending on the context. We also had return codes, but these weren't explicitly defined anywhere.

This makes that convention more explicit and codified. Now to halt the program, the correct thing to do is to throw a cibuildwheel.errors.FatalError exception - that is caught in main() and printed before exiting. The existing behaviour was kept - if an error occurs within a build step (probably something to do with the build itself), the Logger.error() method is used. Outside of a build step (e.g. a misconfiguration), the behaviour is still to print 'cibuildwheel: '

I also took the opportunity to add a debugging option --debug-traceback (and CIBW_DEBUG_TRACEBACK), which you can enable to see a full traceback on errors.

~(I've deactivated the flake8-errmsg lint rule, as it was throwing loads of errors and these error messages aren't generally seen in a traceback context)~

joerick avatar Jan 06 '24 14:01 joerick

A review here would be good too. It's not critical, maybe just a little code quality improvement. I'm not too attached to it though, we could drop the idea if the existing convention approach is preferred.

joerick avatar Mar 02 '24 18:03 joerick

Let's release after this. I've been trying out macOS free threading and build[uv] in some draft PR's,, and have been happy with the results.

henryiii avatar Jun 10 '24 06:06 henryiii