mirror of
https://github.com/block/buzz.git
synced 2026-10-30 22:11:36 +00:00
fix(desktop): preserve deferred upload errors
Signed-off-by: Matt Toohey <contact@matttoohey.com>
This commit is contained in:
@@ -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,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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>) {
|
||||
|
||||
Reference in New Issue
Block a user