message: Improve the error message raised when the source code is not found. Related issue:
diff: @@ -31,9 +31,18 @@ from tensorflow.python.util import tf_inspect
  def parse_entity(entity):
  """Returns the AST of given entity."""
  + try:
  source = tf_inspect.getsource(entity)
  -
  - def fail(comment):
  + except (IOError, OSError) as e:
  + raise ValueError(
  + 'Unable to locate the source code of {}. Note that functions defined'
  + ' in certain environments, like the interactive Python shell do not'
  + ' expose their source code. If that is the case, you should to define'
  + ' them in a .py source file. If you are certain the code is'
  + ' graph-compatible, wrap the call using'
  + ' @tf.autograph.do_not_convert. Original error: {}'.format(entity, e))
  +
  + def raise_parse_failure(comment):
  raise ValueError(
  'Failed to parse source code of {}, which Python reported as:\n{}\n'
  '{}'.format(entity, source, comment))
  @@ -49,7 +58,8 @@ def parse_entity(entity):
  except IndentationError:
  # The text below lists the causes of this error known to us. There may
  # be more.
  - fail('This may be caused by multiline strings or comments not indented at'
  + raise_parse_failure(
  + 'This may be caused by multiline strings or comments not indented at'
  ' the same level as the code.')
  except SyntaxError as e:
  @@ -71,7 +81,8 @@ def parse_entity(entity):
  # Give up if there's nothing we can chip away.
  if len(lines) == lineno and len(lines[-1]) == offset:
  - fail('If this is a lambda function, the error may be avoided by creating'
  + raise_parse_failure(
  + 'If this is a lambda function, the error may be avoided by creating'
  ' the lambda in a standalone statement.')
  # Drop all lines following the error location
  @@ -84,7 +95,8 @@ def parse_entity(entity):
  try:
  return parse_str(new_source), new_source
  except SyntaxError as e:
  - fail('If this is a lambda function, the error may be avoided by creating'
  + raise_parse_failure(
  + 'If this is a lambda function, the error may be avoided by creating'
  ' the lambda in a standalone statement. Tried to strip down the'
  ' source to:\n{}\nBut that did not work.'.format(new_source))
  