Coverage for python/lsst/ctrl/orca/exceptions.py : 28%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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#
24class ConfigurationError(RuntimeError):
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
31class MultiIssueConfigurationError(ConfigurationError):
32 """A configuration error that can report on multiple problems.
34 Parameters
35 ----------
36 msg : `str`, optional
37 The general message to report when more than problem has been encountered. If only one
38 problem is added to this exception, that problem message will be displayed. If None, a
39 generic message is set.
40 problem: `str`, optional
41 The first problem to add to this exception.
43 Extended Summary
44 ---------------
45 The intented pattern of use for this class is that it is
46 created before any problems are found. As they are found,
47 calls are made to addProblem(). Finally, after all possible
48 problems are found, one can call hasProblems(). If it is
49 true, then this exception instance should be raised.
50 """
52 def __init__(self, msg=None, problem=None):
53 if msg is None:
54 msg = "Multiple configuration problems encountered"
55 ConfigurationError.__init__(self, msg)
56 self._probs = []
57 if problem is not None:
58 self.addProblem(problem)
60 def addProblem(self, msg):
61 """Add a message indicating one of the problems encountered
62 """
63 self._probs.append(msg)
65 def hasProblems(self):
66 """
67 Returns
68 -------
69 val : `bool`
70 return True if this exception as at least one problem added to it.
71 """
72 return len(self._probs) > 0
74 def getProblems(self):
75 """
76 Returns
77 -------
78 v : ['string1', 'string2']
79 return a copy of the list of problems
80 """
81 return list(self._probs)
83 # overrides __str__ for custom message
84 def __str__(self):
85 if len(self._probs) < 1:
86 return "Unspecified configuration problems encountered"
87 elif len(self._probs) == 1:
88 return self._probs[0]
89 else:
90 return ConfigurationError.__str__(self)
92 # overrides __repr__ for custom message
93 def __repr__(self):
94 return "MultiIssueConfigurationError: " + str(self)