1# Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Code transformation exceptions.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21from tensorflow.python.autograph.utils import ag_logging 22 23 24class AutoGraphError(Exception): 25 pass 26 27 28class InternalError(AutoGraphError): 29 """Raised when AutoGraph finds an unexpected error.""" 30 31 def __init__(self, message, original_exc): 32 super(InternalError, self).__init__() 33 self.message = message 34 self.original_exc = original_exc 35 36 def __str__(self): 37 return '{} during {}: {}'.format( 38 type(self.original_exc).__name__, self.message, self.original_exc) 39 40 41def report_internal_error(entity, exception): 42 ag_logging.log(1, 'Error transforming %s', entity, exc_info=True) 43 # TODO(znado): Add external bug reporting instructions. 44 raise AutoGraphError( 45 'Unexpected error transforming %s. If you believe this is due to a bug,' 46 ' please set the verbosity to 10 (on Linux, `export ' 47 'AUTOGRAPH_VERBOSITY=10`) and attach the full output when filing the bug ' 48 'report. Caused by: %s' % (entity, exception)) 49