Commit adf0d72
authored
fix(vertex): warn when 'Google Cloud Credentials' field receives a file path (#294)
* fix(vertex): warn when 'Google Cloud Credentials' field receives a file path
Users reported recurring "Error parsing JSON: Unexpected token 'C',
\"C:\\Users\\..\"" spam on every Task creation. Root cause: pasting a
filesystem path into the 'Google Cloud Credentials' field (which expects
raw JSON content), instead of the sibling 'Google Cloud Key File Path'
field. Google's own ecosystem uses GOOGLE_APPLICATION_CREDENTIALS for
paths, so "credentials = path to credentials file" is a natural mental
model that the field naming does not disambiguate.
Three pieces:
- gemini.ts and anthropic-vertex.ts: shape-check the field before
parsing. If it looks like a path (Windows, POSIX absolute, ~/, ./),
log a specific warning pointing at the Key File Path field and the
GOOGLE_APPLICATION_CREDENTIALS env var. Skip the JSON.parse to
avoid the generic 'Error parsing JSON' noise. The shared helper
parseVertexJsonCredentials is exported from gemini.ts and reused
from anthropic-vertex.ts so the Gemini-on-Vertex and Claude-on-Vertex
paths behave identically.
- safeJsonParse: add an optional context arg so logs identify their
source instead of being anonymous. Backward-compatible.
- Vertex.tsx: inline warning under the credentials field that fires
on path-shaped input, naming the correct field to use instead. New
i18n string propagated to all 18 locales.
Auth behavior is unchanged for users who configure the fields correctly
or use the env var. The only user-visible change is the new specific
warning replacing the previous generic spam.
* fix(vertex): bind parsed credentials before truthiness check + extract shared util
Four review items from the PR review round:
- Precedence bug at gemini.ts:225-233 and anthropic-vertex.ts:43-50:
the truthiness check was on the raw vertexJsonCredentials field,
so path-shaped input (which parseVertexJsonCredentials correctly
returns undefined for) still entered the JSON branch with
credentials: undefined instead of falling through to vertexKeyFile.
Bind parseVertexJsonCredentials's result first and branch on it.
- Extract parseVertexJsonCredentials from gemini.ts to a new
utils/vertex-credentials.ts module. anthropic-vertex.ts previously
imported from ./gemini, which pulled in the @google/genai runtime
dependency unnecessarily. The shared util has no provider-specific
imports.
- a11y on the Vertex.tsx warning: added role="alert" and
aria-live="polite" so screen readers announce the dynamic
warning when it appears.
- Mixed-input regression tests: added cases asserting that when
vertexJsonCredentials is path-shaped AND vertexKeyFile is set,
the GoogleAuth/GoogleGenAI client is constructed with the
keyFile, not the (now undefined) credentials. Locks in the
fallback contract. The pre-existing path-shape-only tests were
also updated to match the corrected fallthrough: with no
vertexKeyFile, neither GoogleAuth (anthropic-vertex) nor
googleAuthOptions (gemini) is constructed.
* fix(a11y): use role="status" for the Vertex credentials path warning
role="alert" implies aria-live="assertive" by default, which mixed
awkwardly with the explicit aria-live="polite" override (urgent role
+ don't-interrupt liveness). For an informational warning that fires
as the user types into a settings field, role="status" is the
conventional pattern — implicitly polite, semantically correct for a
non-urgent dynamic message, and removes the role/live conflict.
* fix(vertex): drop path preview from warning + extract shared path-shape predicate
Three review items addressed:
- vertex-credentials.ts: removed the dynamic preview of the user's
input from the warning message — leaking usernames and directory
names into extension logs is mild PII. The static message still
identifies the correct field and the env var to use.
- Extracted the path-shape predicate to @roo-code/types
(packages/types/src/utils/looksLikeFilePath.ts) so the UI warning
in Vertex.tsx and the runtime warning in parseVertexJsonCredentials
share one implementation instead of drifting independently. Both
call sites now import from the shared module; the predicate is
pure, dep-free, regex-based, and covered by its own spec.
- Vertex.spec.tsx: the <Trans> mock now resolves keys against the
real webview-ui English settings.json so the test asserts the
rendered warning text. A future translation regression that
dropped the 'Google Cloud Key File Path' field name or the
GOOGLE_APPLICATION_CREDENTIALS env-var mention from the English
copy would now be caught.
---------
Co-authored-by: 0xMink <260166390+0xMink@users.noreply.github.com>1 parent cef0cc3 commit adf0d72
30 files changed
Lines changed: 624 additions & 13 deletions
File tree
- .changeset
- packages
- core/src/message-utils
- __tests__
- types/src
- __tests__
- utils
- src/api/providers
- __tests__
- utils
- webview-ui/src
- components/settings/providers
- __tests__
- i18n/locales
- ca
- de
- en
- es
- fr
- hi
- id
- it
- ja
- ko
- nl
- pl
- pt-BR
- ru
- tr
- vi
- zh-CN
- zh-TW
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
| |||
14 | 21 | | |
15 | 22 | | |
16 | 23 | | |
17 | | - | |
| 24 | + | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
0 commit comments