fix(models): show real errors when client config import scan fails

importClientConfigs interpolated humanizeError() into a template string;
humanizeError returns an object, so users only saw "[object Object]".

Pass the structured result to toast() with importScanFailed as context.
Add node tests documenting the humanizeError coercion pitfall.

Co-authored-by: 晴天 <1186258278@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-05-18 11:04:43 +00:00
parent 230b5e6dca
commit 291a991dbc
2 changed files with 24 additions and 1 deletions

View File

@@ -1308,7 +1308,7 @@ async function importClientConfigs(page, state) {
const result = await api.scanModelClientConfigs()
candidates = Array.isArray(result?.candidates) ? result.candidates : []
} catch (e) {
toast(`${t('models.importScanFailed')}: ${humanizeError(e)}`, 'error')
toast(humanizeError(e, t('models.importScanFailed')), 'error')
return
} finally {
if (btn) { btn.disabled = false; btn.textContent = oldText || t('models.importClientConfigs') }

View File

@@ -0,0 +1,23 @@
/**
* humanize-error.js contract: return value is a structured object for toast(),
* not for string interpolation (coerces to "[object Object]").
*
* 运行node --test tests/humanize-error.test.js
*/
import test from 'node:test'
import assert from 'node:assert/strict'
import { humanizeError, humanizeErrorText } from '../src/lib/humanize-error.js'
test('humanizeError must not be coerced with String() or template literals', () => {
const h = humanizeError(new Error('ECONNREFUSED 127.0.0.1:443'), 'Import scan failed')
assert.equal(typeof h, 'object')
assert.equal(String(h), '[object Object]')
assert.ok(h.message)
})
test('humanizeErrorText is safe for plain-string contexts', () => {
const line = humanizeErrorText(new Error('ENOENT no such file'), 'Import scan failed')
assert.match(line, /Import scan failed/)
assert.doesNotMatch(line, /\[object Object\]/)
})