fix: harden ssh download stat diagnostics

This commit is contained in:
AgentRun Artificer
2026-06-11 17:15:58 +08:00
parent bb0f0ec497
commit f3055c6617
3 changed files with 82 additions and 12 deletions
+14 -1
View File
@@ -67,11 +67,24 @@ function normalizeErrorPayload(command: string, error: unknown): Record<string,
}
if (error instanceof Error) {
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, message, stack: error.stack ?? null, ...(debug ? { debug: true } : {}) };
return {
name: error.name,
message,
...(sshFileTransferErrorDetails(error) ?? {}),
stack: error.stack ?? null,
...(debug ? { debug: true } : {}),
};
}
return { message };
}
function sshFileTransferErrorDetails(error: Error): Record<string, unknown> | null {
if (error.name !== "SshFileTransferError") return null;
const details = (error as Error & { details?: unknown }).details;
if (typeof details !== "object" || details === null || Array.isArray(details)) return null;
return { details };
}
function parseStructuredErrorMessage(command: string, message: string): Record<string, unknown> | null {
if (!shouldSuppressStack(command) && !shouldSuppressStack(commandPrefixFromMessage(message))) return null;
const jsonStart = message.indexOf("{");