Opened 3 years ago

Last modified 2 years ago

#5474 new defect

Switch assert statements into proper exceptions

Reported by: Christopher Allan Webber Owned by:
Priority: major Milestone: 0.10.0
Component: programming Keywords: small
Cc: Parent Tickets:

Description

See this article; we use assert as a "cheap and easy" way to throw errors if we don't want something, but it's not meant for that... and we might even miss serious / dangerous things. Once python is compiled into bytecode, assert might not run.

Subtickets

Change History (3)

comment:1 Changed 3 years ago by Ben Sturmfels

Keywords: small added

comment:2 Changed 3 years ago by Ben Sturmfels

The following command gives a list of files using assertions (minus tests and third-party code):

$ find -name '*.py' -exec grep -nH -e 'assert ' {} + | grep -v test | grep -v site-packages | grep -v 'Paste-2.0' | grep -v 'tox' | grep -v 'extlib'
./mediagoblin/db/base.py:82:        assert sess is not None, "Can't save, %r has a detached session" % self
./mediagoblin/db/base.py:188:        assert sess is not None, "Not going to delete detached %r" % self
./mediagoblin/db/migration_tools.py:132:        assert self.database_current_migration is not None
./mediagoblin/db/migration_tools.py:263:        assert migration_number > 0, "Migration number must be > 0!"
./mediagoblin/db/migration_tools.py:264:        assert migration_number not in migration_registry, \
./mediagoblin/db/migration_tools.py:266:        assert migration_number <= 44, ('Alembic should be used for '
./mediagoblin/media_types/stl/processing.py:139:        assert os.path.exists(workbench_path)
./mediagoblin/plugins/piwigo/tools.py:99:        assert not cmd_name in self._cmd_table
./mediagoblin/plugins/piwigo/tools.py:104:        assert not self.cmd_name in self._cmd_table
./mediagoblin/plugins/piwigo/tools.py:163:        assert self.in_pwg_session
./mediagoblin/storage/mountstorage.py:70:        assert (len(rem_2) > 0) or (None not in table), \
./mediagoblin/storage/mountstorage.py:72:        assert (len(rem_2) > 0) or (len(table) == 0), \
./mediagoblin/tools/crypto.py:115:    assert __itsda_secret is not None

comment:3 Changed 2 years ago by ShawnRisk

Milestone: 1.00.10.0
Note: See TracTickets for help on using tickets.