OLD | NEW |
| (Empty) |
1 # Copyright 2014 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 import sys | |
6 import traceback | |
7 | |
8 from telemetry import value as value_module | |
9 | |
10 class FailureValue(value_module.Value): | |
11 | |
12 def __init__(self, page, exc_info): | |
13 """A value representing a failure when running the page. | |
14 | |
15 Args: | |
16 page: The page where this failure occurs. | |
17 exc_info: The exception info (sys.exc_info()) corresponding to | |
18 this failure. | |
19 """ | |
20 exc_type = exc_info[0].__name__ | |
21 super(FailureValue, self).__init__(page, exc_type, '', True) | |
22 self._exc_info = exc_info | |
23 | |
24 @classmethod | |
25 def FromMessage(cls, page, message): | |
26 """Creates a failure value for a given string message. | |
27 | |
28 Args: | |
29 page: The page where this failure occurs. | |
30 message: A string message describing the failure. | |
31 """ | |
32 try: | |
33 raise Exception(message) | |
34 except Exception: | |
35 return FailureValue(page, sys.exc_info()) | |
36 | |
37 def __repr__(self): | |
38 if self.page: | |
39 page_name = self.page.url | |
40 else: | |
41 page_name = None | |
42 return 'FailureValue(%s, %s)' % ( | |
43 page_name, GetStringFromExcInfo(self._exc_info)) | |
44 | |
45 @property | |
46 def exc_info(self): | |
47 return self._exc_info | |
48 | |
49 def GetBuildbotDataType(self, output_context): | |
50 return None | |
51 | |
52 def GetBuildbotValue(self): | |
53 return None | |
54 | |
55 def GetBuildbotMeasurementAndTraceNameForPerPageResult(self): | |
56 return None | |
57 | |
58 def GetRepresentativeNumber(self): | |
59 return None | |
60 | |
61 def GetRepresentativeString(self): | |
62 return None | |
63 | |
64 @classmethod | |
65 def GetJSONTypeName(cls): | |
66 return 'failure' | |
67 | |
68 def AsDict(self): | |
69 d = super(FailureValue, self).AsDict() | |
70 d['value'] = GetStringFromExcInfo(self.exc_info) | |
71 return d | |
72 | |
73 @classmethod | |
74 def MergeLikeValuesFromSamePage(cls, values): | |
75 assert False, 'Should not be called.' | |
76 | |
77 @classmethod | |
78 def MergeLikeValuesFromDifferentPages(cls, values, | |
79 group_by_name_suffix=False): | |
80 assert False, 'Should not be called.' | |
81 | |
82 def GetStringFromExcInfo(exc_info): | |
83 return ''.join(traceback.format_exception(*exc_info)) | |
OLD | NEW |