Throw error when invalid file

This commit is contained in:
Akarshan 2025-09-10 12:06:41 +05:30
parent 5ef9d8dfc3
commit 0eff1bfaa9
No known key found for this signature in database
GPG Key ID: D75C9634A870665F

View File

@ -1049,36 +1049,38 @@ export default class llamacpp_extension extends AIEngine {
logger.info(`Installing backend from path: ${path}`) logger.info(`Installing backend from path: ${path}`)
if ((await fs.existsSync(path)) && path.endsWith('tar.gz')) { if ((await fs.existsSync(path)) && path.endsWith('tar.gz')) {
const match = re.exec(archiveName) logger.error(`Invalid path or file ${path}`)
if (!match) throw new Error('Failed to parse archive name') throw new Error(`Invalid path or file ${path}`)
const [, version, backend] = match }
if (!version && !backend) { const match = re.exec(archiveName)
throw new Error(`Invalid backend archive name: ${archiveName}`) if (!match) throw new Error('Failed to parse archive name')
} const [, version, backend] = match
const backendDir = await getBackendDir(backend, version) if (!version && !backend) {
try { throw new Error(`Invalid backend archive name: ${archiveName}`)
await invoke('decompress', { path: path, outputDir: backendDir }) }
} catch (e) { const backendDir = await getBackendDir(backend, version)
logger.error(`Failed to install: ${String(e)}`) try {
} await invoke('decompress', { path: path, outputDir: backendDir })
const binPath = } catch (e) {
platformName === 'win' logger.error(`Failed to install: ${String(e)}`)
? await joinPath([backendDir, 'build', 'bin', 'llama-server.exe']) }
: await joinPath([backendDir, 'build', 'bin', 'llama-server']) const binPath =
platformName === 'win'
? await joinPath([backendDir, 'build', 'bin', 'llama-server.exe'])
: await joinPath([backendDir, 'build', 'bin', 'llama-server'])
if (!fs.existsSync(binPath)) { if (!fs.existsSync(binPath)) {
await fs.rm(backendDir) await fs.rm(backendDir)
throw new Error('Not a supported backend archive!') throw new Error('Not a supported backend archive!')
} }
try { try {
await this.configureBackends() await this.configureBackends()
logger.info(`Backend ${backend}/${version} installed and UI refreshed`) logger.info(`Backend ${backend}/${version} installed and UI refreshed`)
} catch (e) { } catch (e) {
logger.error('Backend installed but failed to refresh UI', e) logger.error('Backend installed but failed to refresh UI', e)
throw new Error( throw new Error(
`Backend installed but failed to refresh UI: ${String(e)}` `Backend installed but failed to refresh UI: ${String(e)}`
) )
}
} }
} }