mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-06-21 15:34:18 +08:00
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:
@@ -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') }
|
||||
|
||||
23
tests/humanize-error.test.js
Normal file
23
tests/humanize-error.test.js
Normal 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\]/)
|
||||
})
|
||||
Reference in New Issue
Block a user