Skip to content

fix: misleading error message upon ImportError with --app argument to CLI#4152

Merged
provinzkraut merged 2 commits intolitestar-org:mainfrom
cstarkers:error-bug-4129
Apr 29, 2025
Merged

fix: misleading error message upon ImportError with --app argument to CLI#4152
provinzkraut merged 2 commits intolitestar-org:mainfrom
cstarkers:error-bug-4129

Conversation

@cstarkers
Copy link
Copy Markdown
Contributor

Description

Fixes #4129

Before this PR, if the --app CLI option is used, any ImportErrors that occur while instantiating the application are assumed to be caused by a bad --app argument. This does not account for cases where the --app option is actually fine, but the ImportError arose from inside the applicaiton code, and this results in a misleading error message.

This PR adds a check on whether the exception resulted from a failure to import the module named in the --app option. If the error arose while attempting some other import, it is not caught. This is consistent with the behaviour that occurs when --app is not used.

@cstarkers cstarkers requested review from a team as code owners April 29, 2025 05:07
@github-actions github-actions bot added area/private-api This PR involves changes to the privatized API size: small type/bug pr/external Triage Required 🏥 This requires triage labels Apr 29, 2025
@cstarkers cstarkers marked this pull request as draft April 29, 2025 05:24
Copy link
Copy Markdown
Member

@provinzkraut provinzkraut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a reasonable fix, thanks!

@provinzkraut provinzkraut marked this pull request as ready for review April 29, 2025 15:04
@provinzkraut provinzkraut enabled auto-merge (squash) April 29, 2025 15:04
@provinzkraut provinzkraut merged commit f6a1dbc into litestar-org:main Apr 29, 2025
47 of 50 checks passed
@github-actions
Copy link
Copy Markdown

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/private-api This PR involves changes to the privatized API pr/external size: small Triage Required 🏥 This requires triage type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Misleading and unhelpful error message upon ImportError with --app argument to CLI

2 participants