diff --git a/starlette/middleware/errors.py b/starlette/middleware/errors.py
index 54f5fd2..b56d6ba 100644
--- a/starlette/middleware/errors.py
+++ b/starlette/middleware/errors.py
@@ -121,7 +121,7 @@ class ServerErrorMiddleware:
             # to optionally raise the error within the test case.
             raise exc from None
 
-    def generate_frame_html(self, frame: traceback.FrameSummary) -> str:
+    def genenrate_frame_html(self, frame: traceback.FrameSummary) -> str:
         values = {
             "frame_filename": frame.filename,
             "frame_lineno": frame.lineno,
@@ -135,7 +135,7 @@ class ServerErrorMiddleware:
             exc, capture_locals=True
         )
         exc_html = "".join(
-            self.generate_frame_html(frame) for frame in traceback_obj.stack
+            self.genenrate_frame_html(frame) for frame in traceback_obj.stack
         )
         error = f"{traceback_obj.exc_type.__name__}: {traceback_obj}"
 
diff --git a/starlette/routing.py b/starlette/routing.py
index d013591..a67bb49 100644
--- a/starlette/routing.py
+++ b/starlette/routing.py
@@ -1,6 +1,7 @@
 import asyncio
 import inspect
 import re
+import traceback
 import typing
 from enum import Enum
 
@@ -469,9 +470,15 @@ class Lifespan(BaseRoute):
     async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
         message = await receive()
         assert message["type"] == "lifespan.startup"
-        await self.startup()
-        await send({"type": "lifespan.startup.complete"})
 
+        try:
+            await self.startup()
+        except BaseException:
+            msg = traceback.format_exc()
+            await send({"type": "lifespan.startup.failed", "message": msg})
+            raise
+
+        await send({"type": "lifespan.startup.complete"})
         message = await receive()
         assert message["type"] == "lifespan.shutdown"
         await self.shutdown()

Error in app startup event is not logged and does not prevent startup
Related #431 #177  and mentioned here https://github.com/encode/uvicorn/issues/333#issuecomment-484885300

Scenario:
I have a 'startup' event handler:
```python
@app.on_event('startup')
async def startup():
    initialise()
```
and I am running under uvicorn for local dev just via the:
```python
if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=8000)
```

If there is an uncaught exception in the startup event handler, the exception will be swallowed (not logged) and uvicorn will continue to startup.

The only anomaly seen in the logs is that uvicorn will report:
```
ASGI 'lifespan' protocol appears unsupported
```

I would like to see:
- the exception and traceback logged
- process aborted, since we haven't fully started up yet


diff --git a/starlette/testclient.py b/starlette/testclient.py
index 7679207..de47f52 100644
--- a/starlette/testclient.py
+++ b/starlette/testclient.py
@@ -463,9 +463,14 @@ class TestClient(requests.Session):
     async def wait_startup(self) -> None:
         await self.receive_queue.put({"type": "lifespan.startup"})
         message = await self.send_queue.get()
-        if message is None:
-            self.task.result()
-        assert message["type"] == "lifespan.startup.complete"
+        assert message["type"] in (
+            "lifespan.startup.complete",
+            "lifespan.startup.failed",
+        )
+        if message["type"] == "lifespan.startup.failed":
+            message = await self.send_queue.get()
+            if message is None:
+                self.task.result()
 
     async def wait_shutdown(self) -> None:
         await self.receive_queue.put({"type": "lifespan.shutdown"})
diff --git a/tests/middleware/test_lifespan.py b/tests/middleware/test_lifespan.py
index 8224689..4f381c1 100644
--- a/tests/middleware/test_lifespan.py
+++ b/tests/middleware/test_lifespan.py
@@ -42,11 +42,22 @@ def test_raise_on_startup():
     def run_startup():
         raise RuntimeError()
 
-    app = Router(routes=[Lifespan(on_startup=run_startup)])
+    router = Router(routes=[Lifespan(on_startup=run_startup)])
 
+    async def app(scope, receive, send):
+        async def _send(message):
+            nonlocal startup_failed
+            if message["type"] == "lifespan.startup.failed":
+                startup_failed = True
+            return await send(message)
+
+        await router(scope, receive, _send)
+
+    startup_failed = False
     with pytest.raises(RuntimeError):
         with TestClient(app):
             pass  # pragma: nocover
+    assert startup_failed
 
 
 def test_raise_on_shutdown():
diff --git a/tests/test_testclient.py b/tests/test_testclient.py
index 1f92c71..6569990 100644
--- a/tests/test_testclient.py
+++ b/tests/test_testclient.py
@@ -1,4 +1,5 @@
 import asyncio
+
 import pytest
 
 from starlette.applications import Starlette

./scripts/install
parse_log_pytest
requirements.txt
pytest
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
aiofiles==23.2.1
aiosqlite==0.19.0
autoflake==2.1.1
Babel==2.14.0
black==23.3.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
charset-normalizer==3.4.1
click==8.1.8
colorama==0.4.6
coverage==7.2.7
databases==0.8.0
exceptiongroup==1.2.2
ghp-import==2.1.0
graphene==3.4.3
graphql-core==3.2.6
graphql-relay==3.2.0
greenlet==3.1.1
idna==3.10
importlib-metadata==6.7.0
iniconfig==2.0.0
isort==5.11.5
itsdangerous==2.1.2
Jinja2==3.1.6
Markdown==3.4.4
MarkupSafe==2.1.5
mergedeep==1.3.4
mkdocs==1.5.3
mkdocs-material==9.2.7
mkdocs-material-extensions==1.2
mypy==1.4.1
mypy-extensions==1.0.0
packaging==24.0
paginate==0.5.7
pathspec==0.11.2
platformdirs==4.0.0
pluggy==1.2.0
pyflakes==3.0.1
Pygments==2.17.2
pymdown-extensions==10.2.1
pytest==7.4.4
pytest-cov==4.1.0
python-dateutil==2.9.0.post0
python-multipart==0.0.8
pytz==2025.2
PyYAML==6.0.1
pyyaml_env_tag==0.1
regex==2022.10.31
requests==2.31.0
six==1.17.0
SQLAlchemy==1.4.54
tomli==2.0.1
typed-ast==1.5.5
typing_extensions==4.7.1
ujson==5.7.0
urllib3==2.0.7
watchdog==3.0.0
zipp==3.15.0

name: starlette
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=2022.12.7=py37h06a4308_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=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - aiofiles==23.2.1
      - aiosqlite==0.19.0
      - autoflake==2.1.1
      - babel==2.14.0
      - black==23.3.0
      - charset-normalizer==3.4.1
      - click==8.1.8
      - colorama==0.4.6
      - coverage==7.2.7
      - databases==0.8.0
      - exceptiongroup==1.2.2
      - ghp-import==2.1.0
      - graphene==3.4.3
      - graphql-core==3.2.6
      - graphql-relay==3.2.0
      - greenlet==3.1.1
      - idna==3.10
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - isort==5.11.5
      - itsdangerous==2.1.2
      - jinja2==3.1.6
      - markdown==3.4.4
      - markupsafe==2.1.5
      - mergedeep==1.3.4
      - mkdocs==1.5.3
      - mkdocs-material==9.2.7
      - mkdocs-material-extensions==1.2
      - mypy==1.4.1
      - mypy-extensions==1.0.0
      - packaging==24.0
      - paginate==0.5.7
      - pathspec==0.11.2
      - platformdirs==4.0.0
      - pluggy==1.2.0
      - pyflakes==3.0.1
      - pygments==2.17.2
      - pymdown-extensions==10.2.1
      - pytest==7.4.4
      - pytest-cov==4.1.0
      - python-dateutil==2.9.0.post0
      - python-multipart==0.0.8
      - pytz==2025.2
      - pyyaml==6.0.1
      - pyyaml-env-tag==0.1
      - regex==2022.10.31
      - requests==2.31.0
      - six==1.17.0
      - sqlalchemy==1.4.54
      - tomli==2.0.1
      - typed-ast==1.5.5
      - typing-extensions==4.7.1
      - ujson==5.7.0
      - urllib3==2.0.7
      - watchdog==3.0.0
      - zipp==3.15.0
prefix: /opt/conda/envs/starlette

tests/middleware/test_lifespan.py::test_raise_on_startup tests/test_testclient.py::test_error_on_startup
tests/middleware/test_lifespan.py::test_routed_lifespan tests/middleware/test_lifespan.py::test_raise_on_shutdown tests/middleware/test_lifespan.py::test_app_lifespan tests/middleware/test_lifespan.py::test_app_async_lifespan tests/test_testclient.py::test_use_testclient_in_endpoint tests/test_testclient.py::testclient_as_contextmanager tests/test_testclient.py::test_testclient_asgi2 tests/test_testclient.py::test_testclient_asgi3 tests/test_testclient.py::test_websocket_blocking_receive
starlette/routing.py starlette/middleware/errors.py
starlette/routing.py starlette/middleware/errors.py