| OLD | NEW |
| 1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import contextlib | 5 import contextlib |
| 6 import functools | 6 import functools |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import traceback | 9 import traceback |
| 10 import urllib | 10 import urllib |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 except Exception as e: | 155 except Exception as e: |
| 156 if isinstance(e, exc_cls): | 156 if isinstance(e, exc_cls): |
| 157 raise | 157 raise |
| 158 else: | 158 else: |
| 159 # Print right away in case the bug is in the stream_engine. | 159 # Print right away in case the bug is in the stream_engine. |
| 160 traceback.print_exc() | 160 traceback.print_exc() |
| 161 print '@@@STEP_EXCEPTION@@@' | 161 print '@@@STEP_EXCEPTION@@@' |
| 162 | 162 |
| 163 if stream_engine: | 163 if stream_engine: |
| 164 # Now do it a little nicer with annotations. | 164 # Now do it a little nicer with annotations. |
| 165 with stream_engine.new_step_stream('Recipe engine bug') as stream: | 165 with stream_engine.make_step_stream('Recipe engine bug') as stream: |
| 166 stream.set_step_status('EXCEPTION') | 166 stream.set_step_status('EXCEPTION') |
| 167 with stream.new_log_stream('exception') as log: | 167 with stream.new_log_stream('exception') as log: |
| 168 log.write_split(traceback.format_exc()) | 168 log.write_split(traceback.format_exc()) |
| 169 stream.add_step_link('file a bug', BUG_LINK) | 169 stream.add_step_link('file a bug', BUG_LINK) |
| 170 sys.stdout.flush() | 170 sys.stdout.flush() |
| 171 sys.stderr.flush() | 171 sys.stderr.flush() |
| 172 os._exit(2) | 172 os._exit(2) |
| 173 | 173 |
| 174 | 174 |
| 175 class StringListIO(object): | 175 class StringListIO(object): |
| 176 def __init__(self): | 176 def __init__(self): |
| 177 self.lines = [StringIO()] | 177 self.lines = [StringIO()] |
| 178 | 178 |
| 179 def write(self, s): | 179 def write(self, s): |
| 180 while s: | 180 while s: |
| 181 i = s.find('\n') | 181 i = s.find('\n') |
| 182 if i == -1: | 182 if i == -1: |
| 183 self.lines[-1].write(s) | 183 self.lines[-1].write(s) |
| 184 break | 184 break |
| 185 self.lines[-1].write(s[:i]) | 185 self.lines[-1].write(s[:i]) |
| 186 self.lines[-1] = self.lines[-1].getvalue() | 186 self.lines[-1] = self.lines[-1].getvalue() |
| 187 self.lines.append(StringIO()) | 187 self.lines.append(StringIO()) |
| 188 s = s[i+1:] | 188 s = s[i+1:] |
| 189 | 189 |
| 190 def close(self): | 190 def close(self): |
| 191 if not isinstance(self.lines[-1], basestring): | 191 if not isinstance(self.lines[-1], basestring): |
| 192 self.lines[-1] = self.lines[-1].getvalue() | 192 self.lines[-1] = self.lines[-1].getvalue() |
| OLD | NEW |