Skip to content

fix(auth): clear errors for missing BL_WORKSPACE/BL_API_KEY (ENG-2253)#153

Merged
mstolarzblaxelai merged 1 commit into
mainfrom
mstolarz/eng-2253-python-sdk-clear-auth-env-var-errors
May 28, 2026
Merged

fix(auth): clear errors for missing BL_WORKSPACE/BL_API_KEY (ENG-2253)#153
mstolarzblaxelai merged 1 commit into
mainfrom
mstolarz/eng-2253-python-sdk-clear-auth-env-var-errors

Conversation

@mstolarzblaxelai
Copy link
Copy Markdown
Contributor

@mstolarzblaxelai mstolarzblaxelai commented May 28, 2026

Fixes ENG-2253.

  • Missing or partial credentials gave cryptic errors: a missing workspace crashed httpx, a missing config file crashed at import, and missing credentials raised an unrelated error or a misleading server-side "workspace is required".
  • The SDK now resolves credentials safely and raises one clear error naming exactly what to set (BL_API_KEY, BL_WORKSPACE, or bl login) before any request goes out.

Note

Replaces cryptic None-propagation failures (httpx encode crash, import-time FileNotFoundError, misleading server-side error) with a MissingCredentials sentinel and CredentialsError that names exactly which env var is missing. Adds _ensure_workspace() guard on every header/auth-flow path, and covers the three failure modes with unit tests.

Written by Mendral for commit 0b408f6.

Partial or absent credentials produced cryptic failures: a None workspace
crashed httpx header encoding, a missing config file crashed at import, and
no credentials surfaced an AttributeError or a misleading server-side
"workspace is required" message.

Resolve credentials safely and fail fast with an actionable message naming
the missing piece (BL_API_KEY / BL_WORKSPACE / `bl login`):
- get_workspace() no longer raises when the config file is absent
- auth() returns a MissingCredentials sentinel instead of None
- workspace is validated before any header is built or token request is made
Copy link
Copy Markdown
Contributor

@mendral-app mendral-app Bot left a comment

Choose a reason for hiding this comment

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

LGTM

The fix is correct and well-scoped. One minor risk: except Exception in get_workspace() silently swallows YAML parse errors on a corrupt config file — the user would see "BL_WORKSPACE missing" rather than "bad YAML", but that's an acceptable trade-off given the stated goal and it's no worse than the pre-existing crash. No blocking issues.

Tag @mendral-app with feedback or questions. View session

@mstolarzblaxelai mstolarzblaxelai merged commit 15178d8 into main May 28, 2026
30 of 32 checks passed
@mstolarzblaxelai mstolarzblaxelai deleted the mstolarz/eng-2253-python-sdk-clear-auth-env-var-errors branch May 28, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant