Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

test(extensions): cover bounded marketplace details

wiiiii123a82637642570
diff --git a/electron/extensions/errorUtils.test.ts b/electron/extensions/errorUtils.test.ts
index 3f35dd2a..7e121411 100644
--- a/electron/extensions/errorUtils.test.ts
+++ b/electron/extensions/errorUtils.test.ts
@@ -28,6 +28,28 @@ describe("formatMarketplaceHttpError", () => {
).toBe("Marketplace request failed (HTTP 400): Invalid search query");
});
+ it("uses a JSON message when an error field is absent", () => {
+ expect(
+ formatMarketplaceHttpError({
+ status: 409,
+ contentType: "application/json",
+ body: JSON.stringify({ message: "Extension version already exists" }),
+ }),
+ ).toBe("Marketplace request failed (HTTP 409): Extension version already exists");
+ });
+
+ it("bounds long JSON details and marks truncation without splitting Unicode", () => {
+ const detail = `πŸš€${"x".repeat(200)}`;
+ const message = formatMarketplaceHttpError({
+ status: 400,
+ contentType: "application/problem+json",
+ body: JSON.stringify({ error: detail }),
+ });
+
+ expect(message).toBe(`Marketplace request failed (HTTP 400): πŸš€${"x".repeat(198)}…`);
+ expect(Array.from(message.split(": ")[1])).toHaveLength(200);
+ });
+
it("does not expose non-JSON response bodies", () => {
expect(
formatMarketplaceHttpError({
diff --git a/electron/extensions/errorUtils.ts b/electron/extensions/errorUtils.ts
index 3119d045..7d44675c 100644
--- a/electron/extensions/errorUtils.ts
+++ b/electron/extensions/errorUtils.ts
@@ -25,10 +25,12 @@ export function formatMarketplaceHttpError({
const { error, message } = payload as { error?: unknown; message?: unknown };
const value = typeof error === "string" ? error : message;
if (typeof value === "string" && value.trim()) {
- detail = value
- .trim()
- .replace(/\s+/g, " ")
- .slice(0, MAX_MARKETPLACE_ERROR_DETAIL_LENGTH);
+ const normalized = value.trim().replace(/\s+/g, " ");
+ const codePoints = Array.from(normalized);
+ detail =
+ codePoints.length > MAX_MARKETPLACE_ERROR_DETAIL_LENGTH
+ ? `${codePoints.slice(0, MAX_MARKETPLACE_ERROR_DETAIL_LENGTH - 1).join("")}…`
+ : normalized;
}
}
} catch {