- Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathexceptions.py
97 lines (79 loc) · 3.52 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
classPlotlyError(Exception):
pass
classPlotlyEmptyDataError(PlotlyError):
pass
classPlotlyGraphObjectError(PlotlyError):
def__init__(self, message="", path=(), notes=()):
"""
General graph object error for validation failures.
:param (str|unicode) message: The error message.
:param (iterable) path: A path pointing to the error.
:param notes: Add additional notes, but keep default exception message.
"""
self.message=message
self.plain_message=message# for backwards compat
self.path=list(path)
self.notes=notes
super(PlotlyGraphObjectError, self).__init__(message)
def__str__(self):
"""This is called by Python to present the error message."""
format_dict= {
"message": self.message,
"path": "["+"][".join(repr(k) forkinself.path) +"]",
"notes": "\n".join(self.notes),
}
return"{message}\n\nPath To Error: {path}\n\n{notes}".format(**format_dict)
classPlotlyDictKeyError(PlotlyGraphObjectError):
def__init__(self, obj, path, notes=()):
"""See PlotlyGraphObjectError.__init__ for param docs."""
format_dict= {"attribute": path[-1], "object_name": obj._name}
message="'{attribute}' is not allowed in '{object_name}'".format(
**format_dict
)
notes= [obj.help(return_help=True)] +list(notes)
super(PlotlyDictKeyError, self).__init__(
message=message, path=path, notes=notes
)
classPlotlyDictValueError(PlotlyGraphObjectError):
def__init__(self, obj, path, notes=()):
"""See PlotlyGraphObjectError.__init__ for param docs."""
format_dict= {"attribute": path[-1], "object_name": obj._name}
message="'{attribute}' has invalid value inside '{object_name}'".format(
**format_dict
)
notes= [obj.help(path[-1], return_help=True)] +list(notes)
super(PlotlyDictValueError, self).__init__(
message=message, notes=notes, path=path
)
classPlotlyListEntryError(PlotlyGraphObjectError):
def__init__(self, obj, path, notes=()):
"""See PlotlyGraphObjectError.__init__ for param docs."""
format_dict= {"index": path[-1], "object_name": obj._name}
message="Invalid entry found in '{object_name}' at index, '{index}'".format(
**format_dict
)
notes= [obj.help(return_help=True)] +list(notes)
super(PlotlyListEntryError, self).__init__(
message=message, path=path, notes=notes
)
classPlotlyDataTypeError(PlotlyGraphObjectError):
def__init__(self, obj, path, notes=()):
"""See PlotlyGraphObjectError.__init__ for param docs."""
format_dict= {"index": path[-1], "object_name": obj._name}
message="Invalid entry found in '{object_name}' at index, '{index}'".format(
**format_dict
)
note="It's invalid because it doesn't contain a valid 'type' value."
notes= [note] +list(notes)
super(PlotlyDataTypeError, self).__init__(
message=message, path=path, notes=notes
)
classPlotlyKeyError(KeyError):
"""
KeyErrors are not printed as beautifully as other errors (this is so that
{}[''] prints "KeyError: ''" and not "KeyError:"). So here we use
LookupError's __str__ to make a PlotlyKeyError object which will print nicer
error messages for KeyErrors.
"""
def__str__(self):
returnLookupError.__str__(self)