question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Builtin vs custom exceptions

See original GitHub issue

Description of issue or feature request: Before releasing TUF 1.0.0 we should review our code and make sure that:

  1. We are using built-in exceptions (ValueError, TypeError, KeyError, etc.) consistently and idiomatically.
  2. We are using custom exceptions when it makes sense and not in places that could be replaced by a built-in exception.

_Initiated from comment https://github.com/theupdateframework/python-tuf/pull/1725#pullrequestreview-856729491_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MVrachevcommented, Feb 2, 2022

We went through this with Martin and came back with this list:

  • verify_signature() should handle SerializationError and throw UnsignedMetadata (this is what callers are interested in)
  • verify_delegate() should document ValueError and TypeError
  • from_securesystemslib_key should raise ValueError if securesystemslib.FormatError is caught
  • All init() and from_dict() should document ValueError (and Keyerror if needed) – the reason this was not done is that this sort of makes it look like programmer should handle these errors… but as long as we are clear in the docstring that these are invalid argument errors, this should be fine

We will file issues for these so there is something actionable. After these issues are filed I believe this meta-issue can be closed

There are issues for all of those:

We can close this issue as it’s a little vague.

0reactions
jkucommented, Feb 2, 2022

We went through this with Martin and came back with this list:

  • verify_signature() should handle SerializationError and throw UnsignedMetadata (this is what callers are interested in)
  • verify_delegate() should document ValueError and TypeError
  • from_securesystemslib_key should raise ValueError if securesystemslib.FormatError is caught
  • All init() and from_dict() should document ValueError (and Keyerror if needed) – the reason this was not done is that this sort of makes it look like programmer should handle these errors… but as long as we are clear in the docstring that these are invalid argument errors, this should be fine

We will file issues for these so there is something actionable. After these issues are filed I believe this meta-issue can be closed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should we use custom exceptions in Python? | by Marcin Kozak
Built-in exceptions offer information about Python-related problems, and custom exceptions will add information about project-related problems.
Read more >
Throwing custom exceptions in Java versus built in exceptions
As a general rule of thumb, when deciding whether or not to create a custom exception class, I try and use the built-in...
Read more >
Understanding, Defining, and Using Custom Exceptions
Custom exceptions are exception types you define yourself in your project. They basically inherit from the Exception base class and implement ...
Read more >
Exception Class and Built-In Exceptions | Apex Reference Guide
An exception denotes an error that disrupts the normal flow of code execution. You can use Apex built-in exceptions or create custom exceptions....
Read more >
Custom exceptions in Python - how and what for?
Exceptions are a standard way of signalling errors in Python. You can improve readability of your code of using custom exceptions classes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found