Skip to content
Documentation menu

Errors & platform helpers

What bunmaska exports for error handling and platform checks: the BunmaskaError family, currentPlatform / isSupported, BUNMASKA_VERSION, and the option types.

Process: Main

Beyond the Electron-shaped modules, the bunmaska barrel exports a small set of helpers you will reach for when an API throws or when you branch per platform. None of these exist in Electron; they are Bunmaska’s own.

Errors

Errors from Bunmaska’s own contracts are a BunmaskaError. Branch on instanceof and on the stable code field, never on message text.

A few throws are deliberately something else, mostly where Electron itself throws a plain type:

  • TypeError - Object has been destroyed from a closed window or its webContents (as in Electron), a malformed webContents.sendInputEvent event, and preload IPC arguments that JSON cannot carry.
  • Error - everything autoUpdater throws or rejects with, and the “not implemented” error the bunmaska/electron shim raises for a known Electron module Bunmaska lacks.
ClasscodeThrown when
BunmaskaErrorundefined on the base classBase class for everything below.
UnsupportedPlatformErrorERR_UNSUPPORTED_PLATFORMAn API is called on a platform that does not support it (e.g. sendInputEvent off Windows).
InvalidArgumentErrorERR_INVALID_ARGUMENTAn argument violates a documented contract - an unknown app.getPath name, a relative app.setPath, protocol.handle on a built-in scheme, a zoom factor that is not above 0, a module-syntax preload a compiled app cannot bundle.
FFIErrorERR_FFIA native library or symbol cannot be loaded or resolved through bun:ffi.
import { app, InvalidArgumentError, UnsupportedPlatformError } from 'bunmaska';

try {
  app.getPath('nope');
} catch (err) {
  if (err instanceof InvalidArgumentError) console.error(err.code, err.message);
}

Warnings

Some calls do not throw but tell you they did nothing useful - openDevTools on Windows, setWindowOpenHandler returning allow, a custom scheme Windows cannot serve. Those warnings (and errors Bunmaska catches for you, such as a throwing IPC listener) go to stderr, prefixed [bunmaska:<module>]. When a page says “logs a warning”, that line is what it means.

Uncaught exceptions

As in Electron, an exception nothing catches in the main process does not take the app down. Once the app has started, Bunmaska logs it and shows an error box (“A JavaScript error occurred in the main process”, stack included), and the app keeps running, slightly embarrassed. That covers a throw from a menu click, a tray click or a global shortcut too: Bunmaska rethrows those on a clean stack rather than letting them unwind into native code. Register your own process.on('uncaughtException', ...) listener and Bunmaska steps aside and lets you handle it.

Platform checks

  • currentPlatform() - returns 'macos' | 'linux' | 'windows' (the Platform type is exported too).
  • isSupported(platform) - true for the platforms Bunmaska runs on.
  • BUNMASKA_VERSION - the framework version string, for logs and about panels.
import { currentPlatform, isSupported, BUNMASKA_VERSION } from 'bunmaska';

console.log(`bunmaska ${BUNMASKA_VERSION} on ${currentPlatform()}`, isSupported(currentPlatform()));

Option types

The option shapes the main-process APIs take are exported for your own signatures: WebPreferences (the BrowserWindow webPreferences bag), LoadFileOptions (webContents.loadFile), MenuPopupOptions (menu.popup), and MouseInputEvent / KeyboardInputEvent (webContents.sendInputEvent).

import type { MenuPopupOptions, WebPreferences } from 'bunmaska';