Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: infra_libs/ts_mon/common/errors.py

Issue 2213143002: Add infra_libs as a bootstrap dependency. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Removed the ugly import hack Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Classes representing errors that can be raised by the monitoring library."""
6
7
8 class MonitoringError(Exception):
9 """Base class for exceptions raised by this module."""
10
11
12 class MonitoringDecreasingValueError(MonitoringError):
13 """Raised when setting a metric value that should increase but doesn't."""
14
15 def __init__(self, metric, old_value, new_value):
16 self.metric = metric
17 self.old_value = old_value
18 self.new_value = new_value
19
20 def __str__(self):
21 return ('Monotonically increasing metric "%s" was given value "%s", which '
22 'is not greater than or equal to "%s".' % (
23 self.metric, self.new_value, self.old_value))
24
25
26 class MonitoringDuplicateRegistrationError(MonitoringError):
27 """Raised when trying to register a metric with the same name as another."""
28
29 def __init__(self, metric):
30 self.metric = metric
31
32 def __str__(self):
33 return 'Different metrics with the same name "%s" were both registered.' % (
34 self.metric)
35
36
37 class MonitoringIncrementUnsetValueError(MonitoringError):
38 """Raised when trying to increment a metric which hasn't been set."""
39
40 def __init__(self, metric):
41 self.metric = metric
42
43 def __str__(self):
44 return 'Metric "%s" was incremented without first setting a value.' % (
45 self.metric)
46
47
48 class MonitoringInvalidValueTypeError(MonitoringError):
49 """Raised when sending a metric value is not a valid type."""
50
51 def __init__(self, metric, value):
52 self.metric = metric
53 self.value = value
54
55 def __str__(self):
56 return 'Metric "%s" was given invalid value "%s" (%s).' % (
57 self.metric, self.value, type(self.value))
58
59
60 class MonitoringInvalidFieldTypeError(MonitoringError):
61 """Raised when sending a metric with a field value of an invalid type."""
62
63 def __init__(self, metric, field, value):
64 self.metric = metric
65 self.field = field
66 self.value = value
67
68 def __str__(self):
69 return 'Metric "%s" was given field "%s" with invalid value "%s" (%s).' % (
70 self.metric, self.field, self.value, type(self.value))
71
72
73 class MonitoringTooManyFieldsError(MonitoringError):
74 """Raised when sending a metric with more than 7 fields."""
75
76 def __init__(self, metric, fields):
77 self.metric = metric
78 self.fields = fields
79
80 def __str__(self):
81 return 'Metric "%s" was given too many (%d > 7) fields: %s.' % (
82 self.metric, len(self.fields), self.fields)
83
84
85 class MonitoringNoConfiguredMonitorError(MonitoringError):
86 """Raised when sending a metric without configuring the global Monitor."""
87
88 def __init__(self, metric):
89 self.metric = metric
90
91 def __str__(self):
92 if self.metric is not None:
93 return 'Metric "%s" was sent before initializing the global Monitor.' % (
94 self.metric)
95 else:
96 return 'Metrics were sent before initializing the global Monitor.'
97
98
99 class MonitoringNoConfiguredTargetError(MonitoringError):
100 """Raised when sending a metric with no global nor local Target."""
101
102 def __init__(self, metric):
103 self.metric = metric
104
105 def __str__(self):
106 return 'Metric "%s" was sent with no Target configured.' % (self.metric)
107
108
109 class UnknownModificationTypeError(MonitoringError):
110 """Raised when using a Modification with an unknown type value."""
111
112 def __init__(self, mod_type):
113 self.mod_type = mod_type
114
115 def __str__(self):
116 return 'Unknown modification type "%s"' % self.mod_type
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698