introduce TestingErrorMeta for internal use (#58917)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58917
In #54780 we opted to return `Optional[Exception]` from all internal
helper functions. Since then multiple PRs added functionality that needs
to amend the error message. For this we recreate the error
https://github.com/pytorch/pytorch/blob/09a1b1cf87fb8724e644693f2c00318ed2637095/torch/testing/_asserts.py#L417-L430
To untangle this a little, this PR introduces the `_TestingErrorMeta`,
which carries the exception type and the message. The idiom
```python
exc = check_foo():
if exc:
return exc
```
is still valid although `exc` should be renamed to `error_meta` to
reflect the new nature. In the top-level functions
`assert_(equal|close)`
```python
exc = check_foo():
if exc:
raise exc
```
changes to
```python
error_meta = check_foo():
if error_meta:
raise error_meta.to_error()
```
Test Plan: Imported from OSS
Reviewed By: anjali411
Differential Revision: D29259405
Pulled By: mruberry
fbshipit-source-id: 9078fe326283d5aa3d0cf256bf007887df9bfbfb