OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
exceptions.py
Go to the documentation of this file.
1 """
2 Define exceptions as specified by the DB API 2.0 spec.
3 
4 Includes some helper methods for translating thrift
5 exceptions to the ones defined here.
6 """
7 from omnisci.thrift.ttypes import TOmniSciException
8 
9 
10 class Warning(Exception):
11  """Emitted for important warnings, e.g. data truncatiions"""
12 
13 
14 class Error(Exception):
15  """Base class for all pymapd errors."""
16 
17 
19  """Raised whenever you use pymapd interface incorrectly."""
20 
21 
23  """Raised when the database encounters an error."""
24 
25 
27  """Raised for data processing errors like division by zero, etc."""
28 
29 
31  """Raised for non-programmer related database errors, e.g.
32  an unexpected disconnect.
33  """
34 
35 
37  """Raised when the relational integrity of the database is affected."""
38 
39 
41  """Raised for errors internal to the database, e.g. and invalid cursor."""
42 
43 
45  """Raised for programming errors, e.g. syntax errors, table already
46  exists.
47  """
48 
49 
51  """Raised when an API not supported by the database is used."""
52 
53 
55  # type: (Exception) -> Exception
56  """Translate a thrift-land exception to a DB-API 2.0
57  exception.
58  """
59  # TODO: see if there's a way to get error codes, rather than relying msgs
60  if not isinstance(e, TOmniSciException):
61  return e
62  if 'Validate failed' in e.error_msg or 'Parse failed' in e.error_msg:
63  err = ProgrammingError
64  elif 'Exception occurred' in e.error_msg:
65  err = DatabaseError
66  else:
67  err = Error
68  return err(e.error_msg)