LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
exceptions.py
Go to the documentation of this file.
1 from builtins import str
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 
25 class ConfigurationError(RuntimeError):
26  """An exception that indicates that an error occurred in the configuration
27  of a production run or one of its components.
28  """
29  pass
30 
31 
33  """A configuration error that can report on multiple problems.
34 
35  Parameters
36  ----------
37  msg : `str`, optional
38  The general message to report when more than problem has been encountered. If only one
39  problem is added to this exception, that problem message will be displayed. If None, a
40  generic message is set.
41  problem: `str`, optional
42  The first problem to add to this exception.
43 
44  Extended Summary
45  ---------------
46  The intented pattern of use for this class is that it is
47  created before any problems are found. As they are found,
48  calls are made to addProblem(). Finally, after all possible
49  problems are found, one can call hasProblems(). If it is
50  true, then this exception instance should be raised.
51  """
52 
53  def __init__(self, msg=None, problem=None):
54  if msg is None:
55  msg = "Multiple configuration problems encountered"
56  ConfigurationError.__init__(self, msg)
57  self._probs = []
58  if problem is not None:
59  self.addProblem(problem)
60 
61  def addProblem(self, msg):
62  """Add a message indicating one of the problems encountered
63  """
64  self._probs.append(msg)
65 
66  def hasProblems(self):
67  """
68  Returns
69  -------
70  val : `bool`
71  return True if this exception as at least one problem added to it.
72  """
73  return len(self._probs) > 0
74 
75  def getProblems(self):
76  """
77  Returns
78  -------
79  v : ['string1', 'string2']
80  return a copy of the list of problems
81  """
82  return list(self._probs)
83 
84  # overrides __str__ for custom message
85  def __str__(self):
86  if len(self._probs) < 1:
87  return "Unspecified configuration problems encountered"
88  elif len(self._probs) == 1:
89  return self._probs[0]
90  else:
91  return ConfigurationError.__str__(self)
92 
93  # overrides __repr__ for custom message
94  def __repr__(self):
95  return "MultiIssueConfigurationError: " + str(self)