diff --git a/pre_commit/commands/migrate_config.py b/pre_commit/commands/migrate_config.py
index d83b8e9..d580ff1 100644
--- a/pre_commit/commands/migrate_config.py
+++ b/pre_commit/commands/migrate_config.py
@@ -2,6 +2,7 @@ import re
 
 import yaml
 
+from pre_commit.clientlib import load_config
 from pre_commit.util import yaml_load
 
 
@@ -43,6 +44,9 @@ def _migrate_sha_to_rev(contents: str) -> str:
 
 
 def migrate_config(config_file: str, quiet: bool = False) -> int:
+    # ensure that the configuration is a valid pre-commit configuration
+    load_config(config_file)
+
     with open(config_file) as f:
         orig_contents = contents = f.read()
 

Unhandled yaml.scanner.ScannerError when trying autoupdate with a malformed pre-commit config
In migrate_config.py we catch `yaml.YAMLError` on [lines 31-36](https://github.com/pre-commit/pre-commit/blob/master/pre_commit/commands/migrate_config.py#L31-L36) (of which `yaml.scanner.ScannerError` is a subclass), but when the exception is raised on line 28, it is unhandled.

```console
$ pre-commit autoupdate
An unexpected error has occurred: ScannerError: mapping values are not allowed in this context
  in "<unicode string>", line 2, column 6
Check the log at /home/ryan/.cache/pre-commit/pre-commit.log
```

### version information

```
pre-commit version: 2.3.0
sys.version:
    3.8.2 (default, Apr  8 2020, 14:31:25) 
    [GCC 9.3.0]
sys.executable: /home/ryan/.local/pipx/venvs/pre-commit/bin/python
os.name: posix
sys.platform: linux
```

### error information

```
An unexpected error has occurred: ScannerError: mapping values are not allowed in this context
  in "<unicode string>", line 2, column 6
```

```
Traceback (most recent call last):
  File "/home/ryan/.local/pipx/venvs/pre-commit/lib/python3.8/site-packages/pre_commit/error_handler.py", line 56, in error_handler
    yield
  File "/home/ryan/.local/pipx/venvs/pre-commit/lib/python3.8/site-packages/pre_commit/main.py", line 354, in main
    return autoupdate(
  File "/home/ryan/.local/pipx/venvs/pre-commit/lib/python3.8/site-packages/pre_commit/commands/autoupdate.py", line 141, in autoupdate
    migrate_config(config_file, quiet=True)
  File "/home/ryan/.local/pipx/venvs/pre-commit/lib/python3.8/site-packages/pre_commit/commands/migrate_config.py", line 49, in migrate_config
    contents = _migrate_map(contents)
  File "/home/ryan/.local/pipx/venvs/pre-commit/lib/python3.8/site-packages/pre_commit/commands/migrate_config.py", line 28, in _migrate_map
    if isinstance(yaml_load(contents), list):
  File "/home/ryan/.local/pipx/venvs/pre-commit/lib/python3.8/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "/home/ryan/.local/pipx/venvs/pre-commit/lib/python3.8/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "ext/_yaml.pyx", line 707, in _yaml.CParser.get_single_node
  File "ext/_yaml.pyx", line 726, in _yaml.CParser._compose_document
  File "ext/_yaml.pyx", line 905, in _yaml.CParser._parse_next_event
yaml.scanner.ScannerError: mapping values are not allowed in this context
  in "<unicode string>", line 2, column 6
```

diff --git a/tests/commands/migrate_config_test.py b/tests/commands/migrate_config_test.py
index efc0d1c..6a049d5 100644
--- a/tests/commands/migrate_config_test.py
+++ b/tests/commands/migrate_config_test.py
@@ -1,6 +1,7 @@
 import pytest
 
 import pre_commit.constants as C
+from pre_commit.clientlib import InvalidConfigError
 from pre_commit.commands.migrate_config import _indent
 from pre_commit.commands.migrate_config import migrate_config
 
@@ -147,10 +148,10 @@ def test_migrate_config_sha_to_rev(tmpdir):
 
 
 @pytest.mark.parametrize('contents', ('', '\n'))
-def test_empty_configuration_file_user_error(tmpdir, contents):
+def test_migrate_config_invalid_configuration(tmpdir, contents):
     cfg = tmpdir.join(C.CONFIG_FILE)
     cfg.write(contents)
-    with tmpdir.as_cwd():
-        assert not migrate_config(C.CONFIG_FILE)
+    with tmpdir.as_cwd(), pytest.raises(InvalidConfigError):
+        migrate_config(C.CONFIG_FILE)
     # even though the config is invalid, this should be a noop
     assert cfg.read() == contents

pip install -e .[dev]
parse_log_pytest
requirements.txt
apt-get update apt-get install -y gcc
3.9
requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
cfgv==3.4.0
covdefaults==2.3.0
coverage==7.8.0
distlib==0.3.9
exceptiongroup==1.2.2
filelock==3.18.0
identify==2.6.9
iniconfig==2.1.0
nodeenv==1.9.1
packaging==24.2
platformdirs==4.3.7
pluggy==1.5.0
-e git+https://github.com/pre-commit/pre-commit.git@46f5cc960947dc0b348a2b19db74e9ac0d5cecf6#egg=pre_commit
pytest==8.3.5
pytest-env==1.1.5
PyYAML==6.0.2
toml==0.10.2
tomli==2.2.1
virtualenv==20.29.3

name: pre-commit
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
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - 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=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - cfgv==3.4.0
      - covdefaults==2.3.0
      - coverage==7.8.0
      - distlib==0.3.9
      - exceptiongroup==1.2.2
      - filelock==3.18.0
      - identify==2.6.9
      - iniconfig==2.1.0
      - nodeenv==1.9.1
      - packaging==24.2
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pytest==8.3.5
      - pytest-env==1.1.5
      - pyyaml==6.0.2
      - toml==0.10.2
      - tomli==2.2.1
      - virtualenv==20.29.3
prefix: /opt/conda/envs/pre-commit

tests/commands/migrate_config_test.py::test_migrate_config_invalid_configuration[] tests/commands/migrate_config_test.py::test_migrate_config_invalid_configuration[\n]
tests/commands/migrate_config_test.py::test_indent[-] tests/commands/migrate_config_test.py::test_indent[a- tests/commands/migrate_config_test.py::test_indent[foo\nbar- tests/commands/migrate_config_test.py::test_indent[foo\n\nbar\n- tests/commands/migrate_config_test.py::test_indent[\n\n\n-\n\n\n] tests/commands/migrate_config_test.py::test_migrate_config_normal_format tests/commands/migrate_config_test.py::test_migrate_config_document_marker tests/commands/migrate_config_test.py::test_migrate_config_list_literal tests/commands/migrate_config_test.py::test_already_migrated_configuration_noop tests/commands/migrate_config_test.py::test_migrate_config_sha_to_rev
pre_commit/commands/migrate_config.py
pre_commit/commands/migrate_config.py