QuTech-Delft / OpenSquirrel

A flexible (Python-based) quantum program compiler
Apache License 2.0
4 stars 1 forks source link

Dont raise bare exceptions #256

Closed S-Linde closed 1 month ago

S-Linde commented 1 month ago

This merge request fixes incorrect error handling. No bare exceptions are raised anywhere in the code. Furthermore, all assert statements are removed except those in the test folders and the check_passes subpackage.

Closes #125

S-Linde commented 1 month ago

Hi Stan,

I've added some final comments:

  • Keep Error clases to store only error messages.
  • Just reuse those error messages, without duplicating any other text (e.g. when creating an ExportError).
  • Rename ExportError to QuantifySchedulerExporterError.
  • Error messages should start in lowercase, and not end in any kind of punctuation. That makes them suitable for inserting in other error messages. This is probably more debatable, but it is the way I'm used to work in C++, and the standard for Rust as well, although may not be the case in Python.

Anyway, think of the ExportError case: you put the UnsupportedGateError in the middle of another message (which is something very common). So you can end up with:

  • Cannot export circuit: The gate is not supported..., or
  • Cannot export circuit: the gate is not supported....

And that should apply to whoever catches an ExportError too:

  • Error: Cannot export..., or
  • Error: cannot export....

Thank you for the detailed explanation. The error message of UnsuportedGateError is now reused and it starts with a lower case and has no punctuation at the end.