Directly raising exception from 'Exception' instance
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- Une demi-journée
- Accessibilité débutants
- 45/100
Piste de recherche
Four bare raise Exception(...) sites are named: b2sdk/sync/action.py (around line 244), b2sdk/v1/download_dest.py (get_bytes_written), and two in b2sdk/v1/sync/folder.py (the except branches for NotADirectory and UnableToCreateDirectory). Read the existing exception classes in the package first, since the issue asks for a more specific built-in or custom exception but does not choose one. Done means each site raises a specific type, the existing tests in the sync and download suites still pass, and callers that catch the old generic exception are checked.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
OpenRefactory introduces fixers, that automatically fix safety, security, reliability and compliance issues. We ran OpenRefactory's Intelligent Code Repair (iCR) analysis engine on your code. We are reporting a few sample fixes that were generated.
Throwing overly broad exceptions promotes complex error handling code that is more likely to contain security vulnerabilities. It will become challenging to catch only specific types of exceptions. The best practice is to catch only exceptions which require specific handling.
Raising Exception in a function will lead to having an except Exception and the only way to differentiate between different exceptions is by comparing the exception messages. Moreover, one could forget to re-raise some exceptions which are unintentionally caught.
OpenRefactory’s Intelligent Code Repair (iCR) for Python, identified four such cases. The diffs are the following:
--- /home/nhasan/ORTest/PythonTest/b2-sdk-python/b2sdk/sync/action.py
+++ /home/nhasan/ORTest/PythonTest/b2-sdk-python/b2sdk/sync/action.py
@@ -241,6 +241,8 @@
except OSError:
pass
if not os.path.isdir(parent_dir):
+ # OpenRefactory Warning: Raising 'Exception' and 'BaseException' directly will have a negative impact on any code trying to catch these exceptions.
+ # Raise a more specific built-in exception or, create a custom one.
raise Exception('could not create directory %s' % (parent_dir,))
def do_action(self, bucket, reporter):
--- /home/nhasan/ORTest/PythonTest/b2-sdk-python/b2sdk/v1/download_dest.py
+++ /home/nhasan/ORTest/PythonTest/b2-sdk-python/b2sdk/v1/download_dest.py
@@ -175,6 +175,8 @@
def get_bytes_written(self):
if self.bytes_written is None:
+ # OpenRefactory Warning: Raising 'Exception' and 'BaseException' directly will have a negative impact on any code trying to catch these exceptions.
+ # Raise a more specific built-in exception or, create a custom one.
raise Exception('data not written yet')
return self.bytes_written
--- /home/nhasan/ORTest/PythonTest/b2-sdk-python/b2sdk/v1/sync/folder.py
+++ /home/nhasan/ORTest/PythonTest/b2-sdk-python/b2sdk/v1/sync/folder.py
@@ -22,6 +22,8 @@
try:
return func(*a, **kw)
except exception.NotADirectory as ex:
+ # OpenRefactory Warning: Raising 'Exception' and 'BaseException' directly will have a negative impact on any code trying to catch these exceptions.
+ # Raise a more specific built-in exception or, create a custom one.
raise Exception('%s is not a directory' % (ex.path,))
except exception.UnableToCreateDirectory as ex:
raise Exception('unable to create directory %s' % (ex.path,))
--- /home/nhasan/ORTest/PythonTest/b2-sdk-python/b2sdk/v1/sync/folder.py
+++ /home/nhasan/ORTest/PythonTest/b2-sdk-python/b2sdk/v1/sync/folder.py
@@ -24,6 +24,8 @@
except exception.NotADirectory as ex:
raise Exception('%s is not a directory' % (ex.path,))
except exception.UnableToCreateDirectory as ex:
+ # OpenRefactory Warning: Raising 'Exception' and 'BaseException' directly will have a negative impact on any code trying to catch these exceptions.
+ # Raise a more specific built-in exception or, create a custom one.
raise Exception('unable to create directory %s' % (ex.path,))
except exception.EmptyDirectory as ex:
raise exception.CommandError(
Reference: CWE-397: Declaration of Throws for Generic Exception
Reported by OpenRefactory’s Intelligent Code Repair (iCR) for Python v1.0. More info at: https://www.openrefactory.com/
- Langage dominant
- Python
- Étoiles
- 214
- Forks
- 68
- Merge moyen
- 51 min
- PR mergées (30 j)
- 6
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de Backblaze/b2-sdk-python
-
Download and copy sync actions print remote file names without escape_control_charsPeut-être pris @dreyfus92 l’a pris il y a 15 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Backblaze/b2-sdk-python#631 ·
Les mainteneurs répondent en général sous 1 jour
-
SqliteAccountInfo profile name validation uses "re.match", so only the first character is checkedPeut-être pris @nazarli-shabnam l’a pris il y a 9 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Backblaze/b2-sdk-python#629 ·
Les mainteneurs répondent en général sous 1 jour
-
Adopt the AI-native SDLC and repository policiesPeut-être pris @goanpeca l’a pris il y a 18 jours. Ouverteenhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
Backblaze/b2-sdk-python#634 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 50/100
Backblaze/b2-sdk-python#630 ·
Les mainteneurs répondent en général sous 1 jour
-
ci: cli-compat fails — 4 sse/sync integration tests broken in B2_Command_Line_Tool (all environments)Peut-être à nouveau libre @ffumero2003 l’a pris il y a 37 jours, et aucune pull request n’est ouverte. Ouvertebug testing
Backblaze/b2-sdk-python#627 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de Backblaze/b2-sdk-python
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
btclib-org/btclib-node#2505 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
open-webui/open-webui#34462 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
gorakhargosh/watchdog#1462 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
openwisp/openwisp-monitoring#889 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
IETF-Hackathon/pqc-certificates#351 ·
Les mainteneurs répondent en général sous 2 jours