fix(desktop): preserve deferred upload errors

Signed-off-by: Matt Toohey <contact@matttoohey.com>
This commit is contained in:
Matt Toohey
2026-08-21 17:03:46 +10:00
parent 0720f5380c
commit 042c636219
2 changed files with 61 additions and 2 deletions

View File

@@ -1,7 +1,12 @@
import assert from "node:assert/strict";
import test from "node:test";
import { mergeMentionRecipients } from "./useMentionSendFlow.helpers.ts";
import {
getErrorMessage,
mergeMentionRecipients,
} from "./useMentionSendFlow.helpers.ts";
const fallback = "Unknown error";
test("address-locked agents join explicit mentions without duplicating recipients", () => {
const explicit = ["A".repeat(64), "b".repeat(64)];
@@ -13,3 +18,51 @@ test("address-locked agents join explicit mentions without duplicating recipient
"c".repeat(64),
]);
});
test("preserves an actionable raw ffmpeg error string", () => {
const error =
"ffmpeg is required for video uploads but was not found.\n\nInstall it:\n macOS: brew install ffmpeg";
assert.equal(getErrorMessage(error, fallback), error);
});
test("preserves an ordinary Error message", () => {
assert.equal(
getErrorMessage(new Error("Video conversion failed"), fallback),
"Video conversion failed",
);
});
test("uses the fallback for empty and whitespace-only text", () => {
for (const error of ["", " \n\t ", new Error(""), new Error(" \n\t ")]) {
assert.equal(getErrorMessage(error, fallback), fallback);
}
});
test("uses the fallback for non-text rejection values", () => {
for (const error of [
null,
undefined,
0,
42,
false,
true,
[],
["Video conversion failed"],
{},
{ message: "Video conversion failed" },
]) {
assert.equal(getErrorMessage(error, fallback), fallback);
}
});
test("preserves original multiline and surrounding whitespace after validation", () => {
const rawString = " \nVideo conversion failed\nTry another file.\n ";
const errorMessage = "\tVideo conversion failed\nDecoder unavailable\t";
assert.equal(getErrorMessage(rawString, fallback), rawString);
assert.equal(
getErrorMessage(new Error(errorMessage), fallback),
errorMessage,
);
});

View File

@@ -82,7 +82,13 @@ export function mergeOutgoingTagsWithReferenceMentions(
}
export function getErrorMessage(error: unknown, fallback: string) {
return error instanceof Error && error.message ? error.message : fallback;
if (error instanceof Error) {
return error.message.trim().length > 0 ? error.message : fallback;
}
if (typeof error === "string") {
return error.trim().length > 0 ? error : fallback;
}
return fallback;
}
export function uniqueNormalizedPubkeys(pubkeys: Iterable<string>) {