Commit 3c6d6c5
committed
fix(cc-switch-import): surface real DB-read error; probe ~/.cc-switch first on all platforms
Two root causes made the cc-switch import repeatedly fail with a misleading
"providers table not found", hiding the actual problem from the user.
1. Error masking: readCcSwitchProviders()'s sqlite_master existence query
had an inner catch {} that swallowed the real error (e.g. "file is not a
database" for a corrupt / non-SQLite cc-switch.db) and collapsed every
failure into the generic "providers table not found" message. The catch is
removed — a throw now propagates to the existing outer catch, which surfaces
`query failed: <real message>`. The genuine table-missing case reports
`providers table not found in <resolved path>` (naming the file so a stale
leftover at a probed path is distinguishable from the real cc-switch DB).
This also satisfies the project rule that swallowed catches with diagnostic
value must not be silent.
2. Path shadowing: candidateDbPaths() probed platform-specific Tauri app-data
paths (~/Library/Application Support/cc-switch/, %APPDATA%\cc-switch\,
~/.local/share/cc-switch/) BEFORE ~/.cc-switch/cc-switch.db, but cc-switch
hardcodes ~/.cc-switch/cc-switch.db on all platforms (get_app_config_dir()
in its config.rs; the Tauri identifier does not affect the DB path). A stale
/ empty leftover file at one of those dead probe paths was matched first
and yielded "providers table not found". ~/.cc-switch/cc-switch.db is now
the primary probe on every platform; the platform paths are demoted to
low-priority legacy fallbacks so they can never shadow the real DB.
Also maps CLAUDE_CODE_EFFORT_LEVEL -> effort in ENV_FIELD_MAP, so a user who
set the effort toggle in cc-switch's "general config" does not silently lose
it on import (the interceptor injects profile.effort as output_config.effort).
Tests: candidateDbPaths() accepts an injectable {plat, home, env} exported as
_candidateDbPathsForTest so the win32/darwin priority ordering is exercised on
any test host (previously zero coverage on non-linux branches). 25 cases:
cross-platform path-priority (win32/darwin/linux, primary wins, stale legacy
file cannot shadow), error-surfacing (non-SQLite file exposes real cause;
valid-but-tableless DB reports distinct message + path), effort mapping
(preserves and empty-default), and live-db integration. Test comments avoid
node-class spawn markers so the env-isolation static guard does not flag the
settings_config / {plat,home,env} data payloads.1 parent e2ddecf commit 3c6d6c5
3 files changed
Lines changed: 185 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
50 | | - | |
51 | | - | |
| 57 | + | |
| 58 | + | |
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
55 | 62 | | |
56 | | - | |
| 63 | + | |
57 | 64 | | |
58 | 65 | | |
59 | 66 | | |
60 | | - | |
61 | | - | |
62 | 67 | | |
63 | 68 | | |
| 69 | + | |
| 70 | + | |
64 | 71 | | |
65 | 72 | | |
66 | 73 | | |
| |||
84 | 91 | | |
85 | 92 | | |
86 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
87 | 98 | | |
88 | 99 | | |
89 | 100 | | |
| |||
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| 120 | + | |
109 | 121 | | |
110 | 122 | | |
111 | 123 | | |
| |||
144 | 156 | | |
145 | 157 | | |
146 | 158 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
154 | 165 | | |
155 | 166 | | |
156 | 167 | | |
| |||
0 commit comments