def EndMapping(self, top_value, mapping):
    """When leaving scope, makes sure new object is initialized.

    This method is mainly for picking up on any missing required attributes.

    Args:
      top_value: Parent of closing mapping object.
      mapping: _ObjectMapper instance that is leaving scope.
    """
    # make sure that mapping.value is a non-built-in type (i.e. can have
    # 'CheckInitialized' called on it)
    if not hasattr(mapping.value, 'CheckInitialized'):
      raise validation.ValidationError('Cannot convert map to non-map value.')

    try:
      mapping.value.CheckInitialized()
    except validation.ValidationError:
      # These should just pass through.
      raise
    except Exception, e:
      # Some errors may have problematic encoding or other issues.
      # Re-raising an error in this block would be very hard to debug
      # for the time being so instead, on error, the value is merely
      # obscured.
      try:
        error_str = str(e)
      except Exception:
        error_str = '<unknown>'

      # Wrap in a ValidationError
      raise validation.ValidationError(error_str, e)