Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Refactoring of return values to Enums or Exceptions #1100

Open
jmcnamara opened this issue Nov 19, 2024 · 2 comments
Open

RFC: Refactoring of return values to Enums or Exceptions #1100

jmcnamara opened this issue Nov 19, 2024 · 2 comments
Labels
awaiting user feedback Waiting for users to answer a question or test a fix. question

Comments

@jmcnamara
Copy link
Owner

jmcnamara commented Nov 19, 2024

Request for Comment

The underlying design for error handling in XlsxWriter is that actions that could cause file corruption or an Excel error (such as duplicate worksheet names) are raised as exceptions. Other "recoverable" actions such as writing to a cell beyond the Excel range are ignored and a negative return value is returned along with a warning. The rationale for return codes/warnings was to allow the overall file creation to complete for more harmless input/parameter errors.

In pratice the return code approach isn't useful for folks who want to handle them programattically due to two issues: the first is that the codes aren't obvioius (-1, -2, etc.) and the second is that they don't correspond to the standard Python exception handling idiom.

As part of the XlsxWriter v2 refactoring/improvements I would like to refactor/improve this in one of two ways:

  • Replace the return codes with IntEnum values like XlsxWriterWarning.RowColumnOutOfBounds. These can be treated as integers or as literals and allows for backward compatibility. This fixes the return code naming issue.
  • Replace the return codes with Exceptions. This is clearly not backward compatible but aligns to the more standard error handling idiom that folks are used to. This will probably cause existing code to break as ignored warnings become exceptions.

I am looking for opinions on this and you can weigh in below if you wish.

See also the previous discussion on this at #892

@jmcnamara jmcnamara added question awaiting user feedback Waiting for users to answer a question or test a fix. labels Nov 19, 2024
@wilcoxon
Copy link

Personally, I strongly prefer return IntEnum. I'm not a fan of raising Exceptions for non-fatal errors.

@ijustlovemath
Copy link

I think the principle of least surprise would dictate exceptions, but that's just me. Raising and handling exceptions is about as Pythonic as it gets (see: how for loops actually work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting user feedback Waiting for users to answer a question or test a fix. question
Projects
None yet
Development

No branches or pull requests

3 participants