Version 13 (modified by 9 years ago) ( diff ) | ,
---|
Exceptions
Custom Trac Exceptions
Trac defines a set of custom exception types:
- Exception
TracBaseError
(trac.core): Exception base class for errors in Trac. (since 1.1.2)TracError
(trac.core): Standard Exception for errors in Trac.AdminCommandError
(trac.admin.api): Exception raised when an admin command cannot be executed.ConfigurationError
(trac.config): Exception raised when a value in the configuration file is not valid.InvalidAttachment
(trac.attachment): Exception raised when attachment validation fails.InvalidRepository
(trac.versioncontrol.api): Exception raised when initializing a repository fails.InvalidTicket
(trac.ticket.web_ui): Exception raised when a ticket fails validation.InvalidWikiPage
(trac.wiki.web_ui): Exception raised when a Wiki page fails validation. Deprecated since Trac 0.11 and removed in Trac 1.1.2.ProcessorError
(trac.wiki.formatter)QuerySyntaxError
(trac.ticket.query): Exception raised when a ticket query cannot be parsed from a string.QueryValueError
(trac.ticket.query): Exception raised when a ticket query has bad constraint values.ResourceNotFound
(trac.resource): Thrown when a non-existent resource is requestedTimeoutError
(trac.db.pool): Exception raised by the connection pool when no connection has become available after a given timeout (Prior to 1.0.2dev-r12305, inherited directly fromException
).
HTTPException
(trac.web.api): Representing a HTTP status codeHTTPBadRequest
(trac.web.api): 400 Bad RequestHTTPUnauthorized
(trac.web.api): 401 UnauthorizedHTTPPaymentRequired
(trac.web.api): 402 Payment RequiredHTTPForbidden
(trac.web.api): 403 ForbiddenHTTPNotFound
(trac.web.api): 404 Not FoundHTTPMethodNotAllowed
(trac.web.api): 405 Method Not AllowedHTTPNotAcceptable
(trac.web.api): 406 Not AcceptableHTTPProxyAuthenticationRequired
(trac.web.api): 407 Proxy Authentication RequiredHTTPRequestTimeout
(trac.web.api): 408 Request TimeoutHTTPConflict
(trac.web.api): 409 ConflictHTTPGone
(trac.web.api): 410 GoneHTTPLengthRequired
(trac.web.api): 411 Length RequiredHTTPPreconditionFailed
(trac.web.api): 412 Precondition FailedHTTPRequestEntityTooLarge
(trac.web.api): 413 Request Entity Too LargeHTTPRequestUriTooLong
(trac.web.api): 414 Request-Uri Too LongHTTPUnsupportedMediaType
(trac.web.api): 415 Unsupported Media TypeHTTPRequestedRangeNotSatisfiable
(trac.web.api): 416 Requested Range Not SatisfiableHTTPExpectationFailed
(trac.web.api): 417 Expectation FailedHTTPInternalError
(trac.web.api): 500 Internal Server ErrorHTTPNotImplemented
(trac.web.api): 501 Not ImplementedHTTPBadGateway
(trac.web.api): 502 Bad Gateway- trac.web.api): 503 Service Unavailable (
HTTPGatewayTimeout
(trac.web.api): 504 Gateway TimeoutHTTPVersionNotSupported
(trac.web.api): 505 Http Version Not Supported
RequestDone
(trac.web.api): Marker exception that indicates whether request processing has completed and a response was sent.ParseError
(trac.versioncontrol.svn_authz): Exception thrown for parse errors in authz filesGitError
(tracopt.versioncontrol.git.PyGIT)GitErrorSha
(tracopt.versioncontrol.git.PyGIT)
Error
(trac.db.tests.api)
- StandardError,
TracBaseError
- StandardError
Hierarchy is inconsistent, even after addition of TracBaseError
class (#11568). There doesn't seem to be any consistent pattern in inheriting from TracError
. Some exceptions also inherit from built-in exception classes other than Exception
.
There also seem to be multiple naming conventions. Consider following PEP:0008#exception-names.
But changing the existing hierarchy might be difficult without breaking backward compatibility.
DB Exceptions
We can catch Python DB API exceptions in a DB-neutral way. (Since Trac 1.0, see #6348.)
try: with env.db_transaction as db: ... except env.db_exc.IntegrityError, e: ...
The above example catches sqlite.IntegrityError
, MySQLdb.IntegrityError
or psycopg.IntegrityError
,
depending on the selected DatabaseBackend.
See tickets