LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
exceptions.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 class ConfigurationError(RuntimeError):
24  """
25  an exception that indicates that an error occurred in the configuration
26  of a production run or one of its components.
27  """
28  pass
29 
31  """
32  a configuration error that can report on multiple problems.
33 
34  The intented pattern of use for this class is that it is
35  created before any problems are found. As they are found,
36  calls are made to addProblem(). Finally, after all possible
37  problems are found, one can call hasProblems(). If it is
38  true, then this exception instance should be raised.
39  """
40 
41  def __init__(self, msg=None, problem=None):
42  """
43  create the exception.
44  @param msg the general message to report when more than problem has
45  been encountered. If only one problem is added to this
46  exception, that problem message will be displayed.
47  If None, a generic message is set.
48  @param problem the first problem to add to this exception.
49  """
50  if msg is None:
51  msg = "Multiple configuration problems encountered"
52  ConfigurationError.__init__(self, msg)
53  self._probs = []
54  if problem is not None:
55  self.addProblem(problem)
56 
57  def addProblem(self, msg):
58  """
59  add a message indicating one of the problems encountered
60  """
61  self._probs.append(msg)
62 
63  def hasProblems(self):
64  """
65  return True if this exception as at least one problem added to it.
66  """
67  return len(self._probs) > 0
68 
69  def getProblems(self):
70  """
71  return a copy of the list of problems
72  """
73  return list(self._probs)
74 
75  ## overrides __str__ for custom message
76  def __str__(self):
77  if len(self._probs) < 1:
78  return "Unspecified configuration problems encountered"
79  elif len(self._probs) == 1:
80  return self._probs[0]
81  else:
82  return ConfigurationError.__str__(self)
83 
84  ## overrides __repr__ for custom message
85  def __repr__(self):
86  return "MultiIssueConfigurationError: " + str(self)
87 
88 
89 
def __repr__
overrides repr for custom message
Definition: exceptions.py:85
def __str__
overrides str for custom message
Definition: exceptions.py:76