Skip to content

Debugging

pam desktop dev is built for a fast loop: it restarts the PHP worker on every save while the window stays open, keeps your state, and turns every uncaught error into a readable report drawn by the host. This page covers that loop and the tools around it: the inspector, logs, static checks and the environment switches that explain what the host is doing.

In pam desktop dev the host checks the project every 150 ms for changed php, pam, json, css, svg, png, jpg and ttf files, skipping dot-directories, vendor, node_modules, dist, target, build, storage, cache and tmp. Once the tree has been quiet for 80 ms it reloads:

  1. The running worker writes a checkpoint of every #[State] property and exits.
  2. A new worker runs the entry script again.
  3. Its first frame is diffed against what is on screen, so the window does not flash.

From save to updated window takes about 0.3 s on Linux. Module state of the old worker is dropped: pending results are discarded, and menus, tray, shortcuts and timers are whatever the new worker registers. Mark secrets and in-flight flags with #[State(hotReload: false)] so they start fresh.

An uncaught error never leaves a blank window. The worker reports it with its phase, the source around the failing line and the call stack, and the host draws the report itself, so it works even when PHP never produced a first frame. Every report is also written to standard error, prefixed with [pam-desktop].

Phase Raised from Fatal
Boot App::run() and what runs before the first render Yes
Render A render() method, a template or the encoder Yes
Event An element, lifecycle or dimension handler No
Module callback A module callback without a failure handler No
Unhandled promise rejection A rejected promise nobody handled No
Worker A fatal PHP error that ends the worker (memory or time limit) Yes

In development, a non-fatal error shows a toast and the application stays usable; pressing the toast opens the full report. A fatal error shows the full report over the window: the type and message, the source in your .pam.php file (never the compiled cache), the call stack with framework frames folded, and Dismiss, Copy and Reload buttons. Fix the source and the overlay clears by itself in about a quarter of a second.

In production (pam desktop run and installed bundles) nothing technical is shown. Non-fatal errors are logged. A fatal error makes the host reload the application after 250 ms, 500 ms and 1 s; after three failures it shows a plain screen with a button to try again.

App::onError() runs for every uncaught error, for example to send it to your logging:

index.php
use Pam\Desktop\App;
use Pam\Desktop\Diagnostics\RuntimeError;
App::onError(function (Throwable $error, RuntimeError $report): void {
error_log(sprintf('[%s] %s at %s:%d', $report->phase->value, $report->message, $report->file, $report->line));
});

To contain a failure to one part of the screen, override failed() in a component and return a fallback element.

In pam desktop dev, press F12 (or Ctrl+Shift+I) to turn the inspector on. The element under the pointer is outlined and a card shows its kind, size and position, every property after state styles and transitions, the states that have styles, the events it listens to and its ancestors. A click pins the element and prints its full description to standard error. F12 or Escape turns it off.

Standard error is the log. PHP warnings, echo, var_dump, error_log() and the host’s own [pam-desktop] messages all appear in the terminal where you started pam desktop dev. Writing to standard output is safe: it is redirected, so it cannot corrupt the frame channel.

Switch Effect
PAM_DESKTOP_DEBUG=1 Logs every pointer press, key press (with modifiers and the focused node) and event sent to PHP.
PAM_DESKTOP_PROFILE=1 Times each interaction: the PHP handler and render, the host layout, the native view work and the painted frame.
PAM_DESKTOP_WINDOW=800x600 Forces the size of the first window.
PAM_DESKTOP_DATA_DIR, PAM_DESKTOP_CACHE_DIR, PAM_DESKTOP_STATE_DIR Isolate a run from the application’s real files.
PAM_DESKTOP_STRICT=1 Makes BuildConfiguration::strict() true in development.
PAM_DESKTOP_DUMP_FRAMES=/tmp/frames.json Writes every node’s frame after each layout change.
PAM_DESKTOP_CAPTURE=/tmp/shot.png macOS: writes the first window to a PNG from inside the process.
Terminal window
PAM_DESKTOP_PROFILE=1 pam desktop dev

A line such as [pam-desktop] frame rejected: … followed by a full re-render points at an encoding problem, not a crash: the host recovered by itself.

pam desktop check validates every template, stylesheet and route without starting the host or opening a window. It runs the entry file up to App::run(), compiles each component into a private temporary cache and lists every diagnostic instead of stopping at the first:

$ pam desktop check
src/Screens/Badge.pam.php:21:1 PAM2403 Expected a native numeric CSS value in src/Screens/Badge.pam.php, got banana
src/Screens/Profile.pam.php:17:9 PAM2401 unknown attribute Text.color, did you mean textColor?
pam-desktop check: 2 diagnostics (12 components in 2 roots).
Code Diagnostic
PAM2400 The entry file failed before App::run().
PAM2401 Template contract: unknown action, prop, event or attribute; missing required prop.
PAM2402 Template or component compile error.
PAM2403 Invalid CSS in a <style> block or stylesheet.
PAM2404 Route error: unknown route, missing or mistyped parameter.
PAM2405 A template expression that cannot run.

It exits 0 when clean and 1 otherwise, so run it first in CI. --json prints machine-readable output, --src=<dir> checks specific directories and --entry=<file> names another entry file.

To run or capture an application on a CI runner or over SSH, start a virtual X server on Linux:

Terminal window
Xvfb :99 -screen 0 1280x800x24 &
DISPLAY=:99 PAM_DESKTOP_WINDOW=1280x800 pam desktop run --yes &
sleep 5 && DISPLAY=:99 import -window root shot.png

When a screen reimplements a web page, compare boxes rather than pixels. Start the application with PAM_DESKTOP_DUMP_FRAMES=/tmp/frames.json: after each layout change the host rewrites the file with one entry per node, including its layout frame on the same 1/64-pixel grid Chromium uses, the content box and the painted frame snapped to device pixels. Without the variable nothing is computed. The PAM Desktop repository has scripts that extract getBoundingClientRect() boxes from a page and report each edge that differs.

Delete .pam-desktop/ to start development from nothing: stored values, databases, caches, the navigation stack, the appearance preference and compiled templates.