diff --git a/docs/changelog.rst b/docs/changelog.rst
index 8b23bbd..f7854e0 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -3,6 +3,7 @@
 =========
 Changelog
 =========
+* :bug:`341` Fail more gracefully when encountering bad metadata
 * :feature:`310` Now provide a more meaningful error on redirect during upload.
 * :release:`1.13.0 <2019-02-13>`
 * :bug:`452 major` Restore prompts while retaining support for suppressing
diff --git a/twine/package.py b/twine/package.py
index c838c88..9fe89d2 100644
--- a/twine/package.py
+++ b/twine/package.py
@@ -84,6 +84,15 @@ class PackageFile(object):
                 os.path.basename(filename)
             )
 
+        # If pkginfo encounters a metadata version it doesn't support, it may
+        # give us back empty metadata. At the very least, we should have a name
+        # and version
+        if not (meta.name and meta.version):
+            raise exceptions.InvalidDistribution(
+                "Invalid distribution metadata. Try upgrading twine if "
+                "possible."
+            )
+
         if dtype == "bdist_egg":
             pkgd = pkg_resources.Distribution.from_filename(filename)
             py_version = pkgd.py_version

twine should fail more gracefully when encountering a metadata version it doesn't support
(It's hard to provide a full reproduce here, so if any of the below isn't clear enough, apologies, but it's a first shot:)

I'm uploading a package (a wheel specifically) generated in the "standard way" with new setuptools and using twine upload, but twine dies by simply saying:

```
⊙  /Users/Julian/Development/Magnetic/Floodgate/.tox/pypy/bin/pypy -m twine upload --repository-url http://127.0.0.1:53385 --username floodgate-unittest-user --password 'some password' /var/folders/kh/mscfrt910qb_qb8wqrz7t_7w0000gn/T/tmp9TRY2p/floodgate_unittest-0.1.0-py2-none-any.whl                                                               Julian@Macnetic
Uploading distributions to http://127.0.0.1:53385
TypeError: must be convertible to a buffer, not None
```

Stepping through with a debugger, it looks like what's failing is that `metadata.name` is `None` in `PackageFile.from_filename`, which `pkg_resources.safe_str` can't cope with (because it regexes it for some reason).

(So that sounds like possibly one improvement, that `None` shouldn't make it all the way down there)

The way it gets to be `None` seems to be that `Distribution.parse` calls `_getHeaderAttrs` to look up a callback to use for extracting metadata for a particular setuptools version, but if the version isn't present, that function returns an empty list, and no metadata is parsed (so `name` is `None`).

Seems like another nice improvement would be failing loudly if the setuptools metadata version isn't supported.
diff --git a/tests/test_package.py b/tests/test_package.py
index 344800c..ecb301a 100644
--- a/tests/test_package.py
+++ b/tests/test_package.py
@@ -13,7 +13,7 @@
 # limitations under the License.
 from __future__ import unicode_literals
 import platform
-from twine import package
+from twine import package, exceptions
 
 import pretend
 import pytest
@@ -208,3 +208,22 @@ def test_no_blake2_hash_manager(monkeypatch):
     hasher.hash()
     hashes = TWINE_1_5_0_WHEEL_HEXDIGEST._replace(blake2=None)
     assert hasher.hexdigest() == hashes
+
+
+def test_pkginfo_returns_no_metadata(monkeypatch):
+    """
+    Fail gracefully if pkginfo can't interpret the metadata (possibly due to
+    seeing a version number it doesn't support yet) and gives us back an
+    'empty' object with no metadata
+    """
+
+    def EmptyDist(filename):
+        return pretend.stub(name=None, version=None)
+
+    monkeypatch.setattr(package, "DIST_TYPES", {"bdist_wheel": EmptyDist})
+    filename = 'tests/fixtures/twine-1.5.0-py2.py3-none-any.whl'
+
+    with pytest.raises(exceptions.InvalidDistribution) as err:
+        package.PackageFile.from_filename(filename, comment=None)
+
+    assert 'Invalid distribution metadata' in err.value.args[0]

pip install -e .[keyring,with-blake2]
parse_log_pytest
requirements.txt
pytest coverage pretend check-manifest flake8 mypy doc8 sphinx sphinx-rtd-theme readme_renderer requests requests-toolbelt tqdm keyring pyblake2
apt-get update apt-get install -y gcc
3.6
docs/requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
attrs==22.2.0
Babel==2.11.0
bleach==4.1.0
build==0.9.0
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
check-manifest==0.48
colorama==0.4.5
coverage==6.2
cryptography==40.0.2
distlib==0.3.9
doc8==0.11.2
docutils==0.17.1
filelock==3.4.1
flake8==5.0.4
idna==3.10
imagesize==1.4.1
importlib-metadata==4.2.0
importlib-resources==5.4.0
iniconfig==1.1.1
jeepney==0.7.1
Jinja2==3.0.3
keyring==23.4.1
MarkupSafe==2.0.1
mccabe==0.7.0
mypy==0.971
mypy-extensions==1.0.0
packaging==21.3
pbr==6.1.1
pep517==0.13.1
pkginfo==1.10.0
platformdirs==2.4.0
pluggy==1.0.0
pretend==1.0.9
py==1.11.0
pyblake2==1.1.2
pycodestyle==2.9.1
pycparser==2.21
pyflakes==2.5.0
Pygments==2.14.0
pyparsing==3.1.4
pytest==7.0.1
pytz==2025.2
readme-renderer==34.0
releases==2.1.1
requests==2.27.1
requests-toolbelt==1.0.0
restructuredtext-lint==1.4.0
rfc3986==1.5.0
SecretStorage==3.3.3
semantic-version==2.6.0
six==1.17.0
snowballstemmer==2.2.0
Sphinx==4.3.2
sphinx-rtd-theme==1.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
stevedore==3.5.2
toml==0.10.2
tomli==1.2.3
tox==3.28.0
tqdm==4.64.1
-e git+https://github.com/pypa/twine.git@77b5c75bd683366bcc475e7ae460b1adb79102b4#egg=twine
typed-ast==1.5.5
typing_extensions==4.1.1
urllib3==1.26.20
virtualenv==20.17.1
webencodings==0.5.1
zipp==3.6.0

name: twine
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - attrs==22.2.0
      - babel==2.11.0
      - bleach==4.1.0
      - build==0.9.0
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - check-manifest==0.48
      - colorama==0.4.5
      - coverage==6.2
      - cryptography==40.0.2
      - distlib==0.3.9
      - doc8==0.11.2
      - docutils==0.17.1
      - filelock==3.4.1
      - flake8==5.0.4
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.2.0
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - jeepney==0.7.1
      - jinja2==3.0.3
      - keyring==23.4.1
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - mypy==0.971
      - mypy-extensions==1.0.0
      - packaging==21.3
      - pbr==6.1.1
      - pep517==0.13.1
      - pkginfo==1.10.0
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - pretend==1.0.9
      - py==1.11.0
      - pyblake2==1.1.2
      - pycodestyle==2.9.1
      - pycparser==2.21
      - pyflakes==2.5.0
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytz==2025.2
      - readme-renderer==34.0
      - releases==2.1.1
      - requests==2.27.1
      - requests-toolbelt==1.0.0
      - restructuredtext-lint==1.4.0
      - rfc3986==1.5.0
      - secretstorage==3.3.3
      - semantic-version==2.6.0
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==4.3.2
      - sphinx-rtd-theme==1.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - stevedore==3.5.2
      - toml==0.10.2
      - tomli==1.2.3
      - tox==3.28.0
      - tqdm==4.64.1
      - typed-ast==1.5.5
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - virtualenv==20.17.1
      - webencodings==0.5.1
      - zipp==3.6.0
prefix: /opt/conda/envs/twine

tests/test_package.py::test_pkginfo_returns_no_metadata
tests/test_package.py::test_sign_file tests/test_package.py::test_sign_file_with_identity tests/test_package.py::test_package_signed_name_is_correct tests/test_package.py::test_metadata_dictionary[None] tests/test_package.py::test_metadata_dictionary[gpg_signature1] tests/test_package.py::test_hash_manager tests/test_package.py::test_fips_hash_manager tests/test_package.py::test_no_blake2_hash_manager
docs/changelog.rst twine/package.py
docs/changelog.rst twine/package.py