# Errors and safe mode

Byte checks PHP before it is saved, records what a saved snippet raises while
it runs, stops a snippet that keeps failing, and can turn every snippet off
while you repair a site.

## Before saving

The workspace checks every changed PHP file before it saves, as
[Workspace](/docs/byte/workspace.md#saving) describes: a syntax error, a shell
execution function or a variable function call stops the save. The check
parses the code without running it, so an error that only happens at run
time passes it. `wp sleek byte test` runs the same check from the terminal;
see [WP-CLI](/docs/byte/cli.md).

## The runtime error log

While a snippet's PHP file is being loaded, Byte records the warnings,
notices, deprecations and errors it raises in the snippet's runtime log, and
also a fatal error that stops the request, when the failing file lies in one
of the snippet sources. Errors raised later, by functions the
file registered on other hooks, are not recorded there; WordPress's own debug
log still catches them.

Each line holds the time, the type, the message and the file and line. The
log lives in `uploads/sleek-byte/error-logs`, which refuses direct web
requests for its files, and is cut back to its latest entries once it passes
100 KB.

**Runtime errors** in the workspace toolbar shows the log of the snippet the
selected file belongs to, and **Clear log** empties it after you confirm, which
cannot be undone. From the terminal,
`wp sleek byte errors list <id>` prints it and `wp sleek byte errors clear <id>`
empties it, where `<id>` is the snippet's folder path inside its source.
`Actions_errorLog` and `Actions_clearErrorLog` do the same over REST.

## When a snippet stops itself

A snippet whose log holds three fatal errors from the last hour stops
loading: none of its files run until the log is cleared or the oldest of
those errors is more than an hour old. The Runtime errors dialog says so when
it happens. Fix the cause in the editor, check it in the
[preview](/docs/byte/snippets/preview.md), save, and clear the log to run the
snippet again.

## Turning a snippet off

To stop one snippet without deleting it, turn off **Enable snippet** in its
configuration and save, run `wp sleek byte snippet disable <id>`, or set
`"enabled": false` in its `snippet.json`.

## Safe mode

Safe mode stops every saved snippet and every preview draft, for when a
snippet keeps a site from loading:

- Add `?sleek-byte-safe-mode=1` to any address while logged in as a user who
  can manage options. From then on none of your requests run snippets for an
  hour, the workspace's own and its preview included, so you can reach the
  workspace and fix the code; other visitors are not affected. The workspace
  shows **Turn off safe mode** while it is on, and `?sleek-byte-safe-mode=0`
  ends it too.
- Define the constant in `wp-config.php` to stop every snippet for every
  request until you remove it:

  ```php
  define('SLEEK_BYTE_DISABLE', true);
  ```

PHP files in the `frontend` context also run under WP-CLI, so a snippet that
breaks every request can break WP-CLI too. Then use the constant, or rename or
remove the snippet's folder in `wp-content/uploads/sleek-byte/` over SFTP.
