tw93/Pake · error · TypeError

Badge count must be a finite number.

Error message

Badge count must be a finite number.

What it means

Pake's badge normalization (in the injected event.js) rejects any badge count that is not a finite JavaScript number. The injected script exposes a setBadge API to the web page; before forwarding it to the native window it validates the value, throwing a TypeError for NaN, Infinity, -Infinity, or non-number types. This guards the native IPC boundary from garbage values.

Solutions

  1. Ensure the caller passes a real number: Number(...) the value before calling setBadge.
  2. Check Number.isFinite(count) at the call site before invoking setBadge.
  3. If the intent is to clear the badge, omit the call or use the API's clear path instead of passing NaN/null.

Example fix

// before
setBadge(unreadCountFromResponse);
// after
const count = Number(unreadCountFromResponse);
if (Number.isFinite(count)) setBadge(count);
Defensive patterns

Strategy: type-guard

Validate before calling

function isValidBadgeCount(v) { return typeof v === 'number' && Number.isFinite(v); }
if (!isValidBadgeCount(raw)) throw new TypeError('Badge count must be a finite number.');

Type guard

const isValidBadgeCount = (v) => typeof v === 'number' && Number.isFinite(v);

Try / catch

try { setBadge(raw); } catch (e) { if (e instanceof TypeError) { console.warn('badge skipped:', raw); } else { throw e; } }

Prevention

When it happens

Trigger: A page (or injected code) calls pake's setBadge with a non-number value (string, undefined, null) or a non-finite number (NaN, Infinity).

Common situations: Page scripts computing a count from a fetch result that returned undefined; a notification counter initialized before data loads (NaN); passing a numeric string like '3' from an input element.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.


AI-assisted analysis of tw93/Pake@c8fe8a3f1a (2026-09-20). Data as JSON: /api/errors/63003deb8a91c813. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/inject/event.js:1315

// pages running inside the webview can drive the macOS dock badge (and
// taskbar badge on Linux/Windows). Installs synchronously instead of waiting
// for DOMContentLoaded so feature-detection on Notification/setAppBadge
// returns the polyfill before site scripts run.
(function () {
  const invoke = window.__TAURI__?.core?.invoke;
  if (!invoke) return;

  let permVal = "granted";
  let lastNotifTime = 0;
  let lastNotif = null;
  // Pages that drive the badge directly via setAppBadge own its lifecycle;
  // notifications-driven counts auto-clear on the next user interaction.
  let pageManagedBadge = false;
  let autoBadgeActive = false;

  const normalizeBadgeCount = (count) => {
    if (typeof count !== "number" || !Number.isFinite(count)) {
      throw new TypeError("Badge count must be a finite number.");
    }
    const normalized = Math.floor(count);
    return normalized > 0 ? Math.min(normalized, 99999) : null;
  };
  const setBadge = (count) => {
    pageManagedBadge = true;
    autoBadgeActive = false;
    return invoke("set_dock_badge", { count }).catch(() => {});
  };
  const clearBadge = () => invoke("clear_dock_badge").catch(() => {});
  const setLabel = (label) => {
    pageManagedBadge = true;
    autoBadgeActive = false;
    return invoke("set_dock_badge_label", { label }).catch(() => {});
  };
  const incrementAutoBadge = () => {
    if (pageManagedBadge) return Promise.resolve();
    autoBadgeActive = true;

View on GitHub (pinned to c8fe8a3f1a)