mirror of
https://github.com/iflytek/skillhub.git
synced 2026-09-15 23:31:10 +00:00
feat(cli): enhance error handling and auto-create output directory
This commit is contained in:
parent
bc9b3d1eb2
commit
d96fb008f9
2 changed files with 21 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { Command } from "commander";
|
||||
import { createWriteStream } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { createWriteStream, mkdirSync } from "node:fs";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { finished } from "node:stream/promises";
|
||||
import { ApiClient } from "../core/api-client.js";
|
||||
import { loadConfigFromProgram } from "../core/config.js";
|
||||
|
|
@ -190,6 +190,14 @@ export function registerDownload(program: Command) {
|
|||
}
|
||||
|
||||
const outPath = resolve(outputDir, `${skillSlug}.zip`);
|
||||
const outDir = dirname(outPath);
|
||||
try {
|
||||
mkdirSync(outDir, { recursive: true });
|
||||
} catch (e: any) {
|
||||
spinner.fail(`Failed to create output directory: ${outDir}`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
const fileStream = createWriteStream(outPath);
|
||||
await finished(body.pipe(fileStream));
|
||||
|
||||
|
|
|
|||
|
|
@ -444,7 +444,17 @@ async function installFromRegistry(
|
|||
const { statusCode, body } = response;
|
||||
|
||||
if (statusCode >= 400) {
|
||||
spinner.fail(`Skill not found: ${ns}/${actualSlug}`);
|
||||
let errorMsg = `Failed to download skill: ${ns}/${actualSlug}`;
|
||||
if (statusCode === 404) {
|
||||
errorMsg = `Skill not found: ${ns}/${actualSlug}`;
|
||||
} else if (statusCode === 403) {
|
||||
errorMsg = `Access denied: ${ns}/${actualSlug}. Check your token permissions.`;
|
||||
} else if (statusCode === 503) {
|
||||
errorMsg = `Service temporarily unavailable. Please try again later.`;
|
||||
} else if (statusCode >= 500) {
|
||||
errorMsg = `Server error (${statusCode}). Please try again later.`;
|
||||
}
|
||||
spinner.fail(errorMsg);
|
||||
await rm(tmpDir, { recursive: true, force: true });
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue