Skip to content

Debugging

When something goes wrong in a PAM Native app, you have five tools, from quickest to deepest:

  1. the error overlay, which shows uncaught exceptions on the device with the file, line and source;
  2. logs from the app process, including your error_log() calls;
  3. the DevTools overlay for frame rate and render cost;
  4. diagnostics snapshots, a redacted JSON picture of the running app;
  5. pam doctor, which checks the toolchain when a build fails.

All of them work while pam dev is running, and none of them is compiled into release builds.

An uncaught exception in a render, an event handler, a native module callback or the app’s boot is reported once to your App::onError() listeners and then to the host, which shows it according to the build type.

In debug builds (pam dev, pam run):

  • Non-fatal errors (event handlers, module callbacks) appear as a compact toast at the bottom of the screen. The app stays interactive. Tap the toast to open the inspector.
  • Fatal errors (render and boot failures) open the full-screen inspector directly.
  • The inspector shows the exception, the app frame, a source snippet and the call stack with your frames first. Copy puts the full report on the clipboard; Reload restarts PHP on the active code; Dismiss hides it.

In release builds users never see a stack trace. Non-fatal errors are logged and delivered to App::onError(). Fatal errors retry with a fresh runtime up to three times, then show a friendly “Something went wrong” screen with a Try again button.

Configure the overlay in pam-native.json:

pam-native.json
{
"devErrorOverlay": true
}
Value Behavior
true or "debug" (default) Overlay in debug builds, friendly fallback in release.
false or "off" Never show the overlay; debug builds behave like release.
"always" Also show the overlay in release builds. Use it only for internal QA builds.

Register listeners before App::run() to send errors to your crash reporter. They run in every build mode:

index.php
<?php
declare(strict_types=1);
use App\Hello;
use App\Support\CrashReporter;
use Pam\Native\App;
use Pam\Native\Diagnostics\RuntimeError;
require __DIR__.'/vendor/autoload.php';
App::onError(static function (Throwable $error, RuntimeError $report): void {
CrashReporter::send(
message: $report->message,
phase: $report->phase->value, // boot, render, event, module, promise
fatal: $report->fatal(),
fingerprint: $report->fingerprint, // stable id for grouping
);
});
App::run(new Hello());

RuntimeError also carries frames (app-relative and classified as app, framework, vendor or internal), appFrame, file, line and, in debug builds, a source snippet. A listener that throws is ignored. Unhandled promise rejections arrive with the promise phase and are never fatal.

A failing native module call goes to its failure handler when you pass one, never to the overlay:

use Pam\Native\Modules\NativeModuleException;
use Pam\Native\Storage\Storage;
Storage::get(
'profile',
fn (?string $json) => $this->showProfile($json),
fn (NativeModuleException $error) => $this->showLoadError($error->getMessage()),
);

Without a handler, the failure is reported as a non-fatal NativeModuleException.

Stream the logs of the running app:

Terminal window
pam logs

pam logs runs adb logcat filtered to the app’s process, so the app must be running. Useful tags:

Tag Contents
PamPHP Output of PHP’s error_log() and logged PHP errors.
PamNative The native bridge and runtime.
PamNativeErrors Errors in release builds.
PamNativeHotReload The hot reload client.

Write your own diagnostics with error_log():

error_log(sprintf('checkout: %d items, total %s', count($this->items), $this->total));

Remove noisy logging before release: logs cost CPU and battery, and they can leak personal data.

Debug builds include an on-device performance overlay. With the app running, toggle it from another terminal:

Terminal window
pam devtools

Run it again to hide it. On iOS use pam ios:devtools. The overlay shows the smoothed frame rate, decode and mount time, rendered nodes and batches, patch versus full commits, native heap and the last eight capability events (module latency, failures, lifecycle changes and runtime errors). See DevTools for the profiling workflow.

pam diagnostics captures a redacted JSON snapshot of the running debug app and prints it:

Terminal window
pam diagnostics > artifacts/snapshot.json

The snapshot contains aggregated metrics, hot reload timings and a timeline of the latest eight events. It never contains URLs, headers, bodies, labels or your error messages, so it is safe to attach to an issue. It is capped at 64 KiB.

pam diagnostics picks the running Android app, or the iOS Simulator on a Mac when no Android app is running. Be explicit when you need to:

Terminal window
pam android:diagnostics --device R58M1234 # a specific Android device
pam ios:diagnostics # the booted iOS Simulator

Turn a snapshot into a Chrome Trace Event file and open it in any trace viewer:

Terminal window
pam timeline artifacts/snapshot.json --output artifacts/timeline.json

Capture the device screen into the project:

Terminal window
pam screenshot # artifacts/screenshots/android.png
pam screenshot --output artifacts/screenshots/home.png
pam ios:screenshot # artifacts/screenshots/ios.png

The output must be a project-relative .png path. An existing file is never overwritten unless you add --force, so reference screenshots are not replaced by accident.

Always check the top and bottom edges in screenshots: no text or button may sit under the status bar, a notch, the navigation bar or the home indicator. See Safe Areas.

Hot reload has its own guide: Hot Reload. The most common fixes:

  • After adding a plugin, changing permissions or editing pam-native.json, stop pam dev and start it again; those changes need a native rebuild.
  • With several devices connected, set ANDROID_SERIAL.
  • If the app is already installed and you only restarted the terminal, run pam native dev:serve to start the sync server without rebuilding.
Message Cause and fix
Android SDK not found; set ANDROID_HOME Export ANDROID_HOME; see Installation.
Android Command-line Tools are missing … Install Android SDK Command-line Tools (latest) in the SDK Manager, then pam doctor --fix.
no Android device is connected (adb devices lists none) Connect a device with USB debugging, or start an emulator.
… Android devices are connected …; set ANDROID_SERIAL … Choose one: ANDROID_SERIAL=<serial> pam dev.
… is not running on the connected Android device pam logs and pam diagnostics need the app running; start it with pam dev or pam run.
no booted iOS simulator; open Simulator or run xcrun simctl boot <udid> Boot a simulator before pam ios:dev or pam ios:run.
PAM Native commands require pam composer require pushinbr/pam-native Dependencies are not installed: run pam composer install.
Unknown Pam Native class … A template uses a utility class the active theme does not define. Check App::theme() in index.php, or define the class in <style scoped>.
Template expression $x is undefined … The template reads a name that is not a loop variable, a component property or an App::global().
ProtocolMismatchException The installed host is older than the PHP SDK. Restart pam dev (or rebuild) after updating pushinbr/pam-native.

When a build fails, run pam doctor first: it names the missing tool and the fix. For a support request, pam support --output pam-support.json creates a bounded, redacted report without file contents, environment variables or network data.

  • DevTools: profile render cost on a device.
  • Testing: reproduce a bug in a test without a device.
  • Performance: keep frames smooth and resources low.