fix: raise LangfuseAuthCheckError instead of bare Exception in auth_check()#1771
Open
mittalpk wants to merge 1 commit into
Open
fix: raise LangfuseAuthCheckError instead of bare Exception in auth_check()#1771mittalpk wants to merge 1 commit into
mittalpk wants to merge 1 commit into
Conversation
…heck() auth_check() previously raised a bare Exception when no project was found for the provided credentials, which is easy to swallow with a broad `except Exception` at the call site and hides real bugs (issue langfuse#906).
mittalpk
force-pushed
the
fix/auth-check-bare-exception
branch
from
July 21, 2026 22:41
ddf722c to
53e4e96
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #906
What does this PR do?
Langfuse.auth_check()raised a bareExceptionwhen no project was found for the provided credentials. A bareExceptionis easy to swallow accidentally with a broadexcept Exception:at the call site (a common defensive-coding pattern in application code), which hides a genuine "your API keys don't correspond to a project" failure instead of letting the caller distinguish it from other errors — exactly the scenario described in #906.LangfuseAuthCheckError(Exception)inlangfuse/_client/client.py, exported it publicly inlangfuse/__init__.py(following the existing precedent ofRegressionErrorfromexperiment.py).auth_check()now raisesLangfuseAuthCheckErrorinstead of a bareExceptionin the "no project found" case; updated the docstring accordingly.LangfuseAuthCheckErrorsubclassesExceptiondirectly, so any existingexcept Exception:call site still catches it.Type of change
Verification
All clean; full unit suite passing with no regressions. Added
tests/unit/test_auth_check.pycovering both the new exception being raised when no projects are found, and the happy path being unaffected. Confirmed the new test fails against the pre-fix code (ImportError: cannot import name 'LangfuseAuthCheckError') before the fix is applied.Checklist
code_review.md..env.templateif needed. (docstring updated; no example/.env.templatechanges needed)Greptile Summary
This PR introduces a specific error for failed authentication checks. The main changes are:
LangfuseAuthCheckError.Confidence Score: 5/5
This looks safe to merge.
Reviews (1): Last reviewed commit: "fix: raise LangfuseAuthCheckError instea..." | Re-trigger Greptile
Context used:
Learned From
langfuse/langfuse-python#1387