Debugging
When something goes wrong in a PAM Native app, you have five tools, from quickest to deepest:
- the error overlay, which shows uncaught exceptions on the device with the file, line and source;
- logs from the app process, including your
error_log()calls; - the DevTools overlay for frame rate and render cost;
- diagnostics snapshots, a redacted JSON picture of the running app;
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.
The error overlay
Section titled “The error overlay”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:
{ "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. |
Reporting errors
Section titled “Reporting errors”Register listeners before App::run() to send errors to your crash reporter. They
run in every build mode:
<?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.
Module failures
Section titled “Module failures”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:
pam logspam 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. |
pam ios:logsStreams the unified log of the app’s process on the booted simulator.
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.
DevTools
Section titled “DevTools”Debug builds include an on-device performance overlay. With the app running, toggle it from another terminal:
pam devtoolsRun 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.
Diagnostics snapshots
Section titled “Diagnostics snapshots”pam diagnostics captures a redacted JSON snapshot of the running debug app and
prints it:
pam diagnostics > artifacts/snapshot.jsonThe 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:
pam android:diagnostics --device R58M1234 # a specific Android devicepam ios:diagnostics # the booted iOS SimulatorTurn a snapshot into a Chrome Trace Event file and open it in any trace viewer:
pam timeline artifacts/snapshot.json --output artifacts/timeline.jsonScreenshots
Section titled “Screenshots”Capture the device screen into the project:
pam screenshot # artifacts/screenshots/android.pngpam screenshot --output artifacts/screenshots/home.pngpam ios:screenshot # artifacts/screenshots/ios.pngThe 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 problems
Section titled “Hot reload problems”Hot reload has its own guide: Hot Reload. The most common fixes:
- After adding a plugin, changing permissions or editing
pam-native.json, stoppam devand 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:serveto start the sync server without rebuilding.
Common errors
Section titled “Common errors”| 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.
Next steps
Section titled “Next steps”- DevTools: profile render cost on a device.
- Testing: reproduce a bug in a test without a device.
- Performance: keep frames smooth and resources low.