fix: improve trans script migration hint

This commit is contained in:
Codex
2026-06-20 07:23:11 +00:00
parent d05b963064
commit 4d4feacb31
7 changed files with 133 additions and 13 deletions
+16
View File
@@ -66,6 +66,8 @@ function normalizeErrorPayload(command: string, error: unknown): Record<string,
return { message };
}
if (error instanceof Error) {
const structured = structuredCliErrorPayload(error, message);
if (structured !== null) return structured;
const debug = process.env.UNIDESK_CLI_DEBUG === "1" || process.env.UNIDESK_CLI_FULL_ERROR === "1" || process.env.UNIDESK_CLI_RAW_ERROR === "1";
return {
name: error.name,
@@ -78,6 +80,20 @@ function normalizeErrorPayload(command: string, error: unknown): Record<string,
return { message };
}
function structuredCliErrorPayload(error: Error, message: string): Record<string, unknown> | null {
const record = error as Error & Record<string, unknown>;
if (!Object.prototype.hasOwnProperty.call(record, "replacementExamples") && !Object.prototype.hasOwnProperty.call(record, "migrationHint")) return null;
const payload: Record<string, unknown> = {
name: error.name,
message,
};
for (const key of ["code", "level", "entrypoint", "route", "operation", "replacementExamples", "migrationHint", "note"]) {
const value = record[key];
if (value !== undefined) payload[key] = value;
}
return payload;
}
function sshFileTransferErrorDetails(error: Error): Record<string, unknown> | null {
if (error.name !== "SshFileTransferError") return null;
const details = (error as Error & { details?: unknown }).details;