Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class names are also made relative when they point inside the application direct

The exception's origin and every frame carry one `source` string: the source line at the reported `line`, trimmed
of surrounding whitespace. A blank line is an empty string. Unavailable source is omitted. Traces are capped at
30 frames (`traceLimit`), keeping the frames nearest the throw; a capped trace is flagged with `traceTruncated`.
30 frames (`traceLimit`), keeping the frames nearest the throw; a capped trace is flagged with `truncated`.

Frame arguments are included, truncated to depth 5, 50 items, and 500 bytes per string. Objects are reduced to a
class name plus at most 50 public properties, with the remainder reported by the same `"*truncated*": "N more
items"` marker used for maps. `#[\SensitiveParameter]` values are redacted, and `__toString()` is never called.
A frame whose arguments PHP did not report carries no `args` member at all.
Frame arguments are reduced to their types, never their values: `args` is a list of type names such as `int`,
`string`, `bool`, `null`, `float`, `Closure`, a class name, or `resource (stream)`. An array is `vec` when it is a
list and `dict` otherwise. A `#[\SensitiveParameter]` argument reports the type of the protected value, never the
value. A frame whose arguments PHP did not report carries no `args` member at all.

**Arguments require `zend.exception_ignore_args=Off`.** It defaults to `Off`, and `php.ini-development` sets
`Off`, but `php.ini-production` sets `On`, which removes arguments from every trace PHP produces. An application
Expand Down Expand Up @@ -105,20 +105,21 @@ After running `composer install` (including development dependencies), start the
php -S localhost:8000 demo/index.php
```

Open <http://localhost:8000/> for a centered grid of links. The same router serves all four demos, each intentionally
Open <http://localhost:8000/> for a centered grid of links. The same router serves all five demos, each intentionally
returning a 500 `application/problem+json` response through `ExceptionMiddleware`:

- `/minimal`: production-style output without the exception message, source, or trace.
- `/full`: the same exception with development details.
- `/recursion`: bounded recursive object calls with cyclic public properties and a truncated trace.
- `/sensitive`: redacted parameter arguments and public properties wrapped in `SensitiveParameterValue`.
- `/recursion`: bounded recursive calls that produce a truncated trace.
- `/sensitive`: a `#[\SensitiveParameter]` argument reduced to its type, never its value.
- `/types`: a call with scalar, `vec`, `dict`, object, enum, and closure arguments, each shown as its type.

You can also request a demo directly, for example with `curl -i http://localhost:8000/full`.

Development demos enable exception arguments regardless of your `php.ini`. The sensitive demo accepts optional
`DEMO_PASSWORD` and `DEMO_TOKEN` environment variables; its defaults are fake credentials. `#[SensitiveParameter]`
protects trace arguments, not stored properties, exception messages, or source code. Use `SensitiveParameterValue`
for sensitive public properties and never put real secrets in messages or source files.
`DEMO_PASSWORD` and `DEMO_TOKEN` environment variables; its defaults are fake credentials. Because traces carry
argument types only, no argument value ever reaches the response; `#[\SensitiveParameter]` is still respected.
Never put real secrets in exception messages or source files.

## Development

Expand Down
2 changes: 2 additions & 0 deletions demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'/full' => 'full.php',
'/recursion' => 'recursion.php',
'/sensitive' => 'sensitive.php',
'/types' => 'types.php',
default => null,
};

Expand Down Expand Up @@ -89,6 +90,7 @@
<a href="/full">full</a>
<a href="/recursion">recursion</a>
<a href="/sensitive">sensitive</a>
<a href="/types">types</a>
</nav>
</main>
</body>
Expand Down
8 changes: 1 addition & 7 deletions demo/recursion.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
*/
final class RecursiveNode
{
public self $next;

public function __construct(
public readonly string $name,
) {
$this->next = $this;
}
) {}

public function visit(self $node, int $remaining): never
{
Expand All @@ -35,8 +31,6 @@ public function visit(self $node, int $remaining): never
namespace\run_demo(Mode::Full, static function (): never {
$first = new RecursiveNode('first');
$second = new RecursiveNode('second');
$first->next = $second;
$second->next = $first;

$first->visit($second, 35);
});
62 changes: 62 additions & 0 deletions demo/types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Errata\Demo;

use Closure;
use Errata\Mode;
use RuntimeException;
use stdClass;

use function count;

require_once __DIR__ . '/bootstrap.php';

/**
* @internal
*/
final class TypedCaller
{
/**
* @param list<int> $items
* @param array<string, int> $counts
*/
// @mago-ignore lint:excessive-parameter-list
public function call(
int $count,
string $label,
// @mago-ignore lint:no-boolean-flag-parameter
bool $enabled,
?string $note,
float $ratio,
array $items,
array $counts,
stdClass $payload,
Mode $mode,
Closure $callback,
): never {
$callback();

$summary = $label . ':' . $count . ':' . count($items) . ':' . count($counts);
$summary .= ':' . $payload::class . ':' . $mode->name;
$summary .= ':' . ($enabled ? 'on' : 'off') . ':' . ($note ?? 'none') . ':' . $ratio;

throw new RuntimeException('The typed-arguments demo always fails: ' . $summary);
}
}

namespace\run_demo(Mode::Full, static function (): never {
new TypedCaller()->call(
count: 3,
label: 'demo',
enabled: true,
note: null,
ratio: 0.5,
items: [1, 2, 3],
counts: ['a' => 1, 'b' => 2],
payload: new stdClass(),
mode: Mode::Full,
callback: static fn(): int => 1,
);
});
Loading
Loading