Download the PHP package raffaelecarelle/php-error-insight without Composer
On this page you can find all versions of the php package raffaelecarelle/php-error-insight. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download raffaelecarelle/php-error-insight
More information about raffaelecarelle/php-error-insight
Files in raffaelecarelle/php-error-insight
Package php-error-insight
Short Description AI-powered helper for PHP errors, warnings and exceptions: practical, context-aware explanations and suggestions via local or API LLMs.
License GPL-3.0-or-later
Informations about the package php-error-insight
PHP Error Insight
A tool that intercepts PHP errors, warnings, and exceptions and provides practical help and advice generated by AI (local models or external APIs). No static text: details and suggestions are created on-the-fly by artificial intelligence based on the error message and context.
Screenshots:
- Supports local AI backends (e.g. Ollama/LocalAI) and APIs (e.g. OpenAI, Anthropic, Google Gemini).
- HTML, text or JSON output.
- Simple configuration via environment variables or by instantiating the Config.
Requirements
- PHP >= 8.1
- Composer
- (Optional) a local AI backend (Ollama/LocalAI) or an API key (OpenAI, etc.)
Installation
Configuration
You can configure the tool via environment variables or through code.
Supported environment variables:
- PHP_ERROR_INSIGHT_ENABLED: true/false (default: true)
- PHP_ERROR_INSIGHT_BACKEND: none|local|api|openai|anthropic|google|gemini
- PHP_ERROR_INSIGHT_MODEL: model name (e.g. llama3:instruct, gpt-4o-mini, claude-3-5-sonnet-20240620, gemini-1.5-flash)
- PHP_ERROR_INSIGHT_API_KEY: API key (required for api/openai/anthropic/google backends)
- PHP_ERROR_INSIGHT_API_URL: service URL (optional override; e.g. http://localhost:11434 for Ollama, https://api.openai.com/v1/chat/completions for OpenAI, https://api.anthropic.com/v1/messages for Anthropic, https://generativelanguage.googleapis.com/v1/models for Google Gemini)
- PHP_ERROR_INSIGHT_LANG: language for AI prompt (it, en, ...; default: it)
- PHP_ERROR_INSIGHT_OUTPUT: auto|html|text|json (default: auto)
- PHP_ERROR_INSIGHT_VERBOSE: true/false (default: false)
- PHP_ERROR_INSIGHT_TEMPLATE: path to a custom HTML template (optional)
- PHP_ERROR_INSIGHT_ROOT: absolute project root to compute relative file paths in the stack (optional)
- PHP_ERROR_INSIGHT_HOST_ROOT: absolute host project root used to map container paths when opening files via editor links (optional; useful in Docker)
- PHP_ERROR_INSIGHT_EDITOR: editor URL template for clickable file links, using %file and %line placeholders (e.g. "vscode://file/%file:%line" or "phpstorm://open?file=%file&line=%line")
- PHP_ERROR_INSIGHT_CONSOLE_COLORS: JSON object to customize console styles (token colors, severity backgrounds, title/suggestions/stack/location).
Configuration examples:
1) Local backend (Ollama):
2) API backend (OpenAI compatible):
3) API backend (Anthropic Claude):
4) API backend (Google Gemini):
Editor integration and stack trace copying
When viewing the HTML error page, each stack frame now shows:
- Clickable file path: if PHP_ERROR_INSIGHT_EDITOR (or Config::editorUrl) is set, file paths become links that can open your editor at the exact line.
- Per-row copy button: a small clipboard button copies the project-relative path with line in the format
path/to/file.php:LINE. - Copy title: a button in the header copies the error title (and location) to your clipboard.
- Copy full stack: a button copies all stack lines as plain text.
Configuration options:
- PHP_ERROR_INSIGHT_ROOT: absolute project root used to compute relative paths.
- PHP_ERROR_INSIGHT_EDITOR: URL template with placeholders %file and %line.
- VS Code:
vscode://file/%file:%line - PhpStorm:
phpstorm://open?file=%file&line=%line
- VS Code:
Example (VS Code):
Example (PhpStorm):
Docker/containers mapping (open files in host IDE):
When running the app inside a container, set PHP_ERROR_INSIGHT_ROOT to the container project root and PHP_ERROR_INSIGHT_HOST_ROOT to the corresponding host path. Editor links will be generated with the host path so your IDE can open files.
Example (Docker + VS Code):
Example (Docker + PhpStorm):
Code-based configuration example:
Notes:
- If a file is outside the declared project root, the viewer falls back to trimming from
/vendor/when present, or shows a normalized absolute path. - All clipboard features use a secure helper that falls back to a hidden textarea when the Clipboard API is not available.
Usage (Vanilla PHP)
In your application's bootstrap, register the handler. A minimal example is available in examples/vanilla/index.php.
Quick example:
Output:
- In HTML you'll see the page with stack trace and the "Details/Suggestions" section populated by AI.
- In CLI you'll get text/JSON depending on configuration.
Usage with PHPUnit
To use PHP Error Insight with PHPUnit, you can register the error handler in your PHPUnit bootstrap file. This will catch errors that occur during your test runs and provide detailed, AI-powered explanations.
First, ensure your phpunit.xml or phpunit.xml.dist is configured to use a bootstrap file:
Then, in your tests/bootstrap.php file, register the error handler:
Now, when you run PHPUnit, any errors will be processed by PHP Error Insight, and you'll see the enhanced error output directly in your console.
How it works
- The tool intercepts errors/warnings/exceptions.
- Builds a prompt with message, severity and location.
- Sends the prompt to the configured AI backend.
- Shows the AI response as details and practical suggestions.
Note: the tool no longer uses static translated texts for details/suggestions. If the AI backend is not configured or doesn't respond, those sections might remain empty.
Privacy and Data Sanitization
Automatic Sanitization of Sensitive Parameters
PHP Error Insight automatically sanitizes sensitive data to prevent leakage in AI prompts. The sanitization system supports two main features:
1. Sensitive Parameter Detection
Function and method parameters marked with the #[SensitiveParameter] attribute are automatically redacted in stack traces:
How it works:
- The system uses PHP's Reflection API to detect parameters with
#[SensitiveParameter]attribute - Arguments are sanitized automatically when building stack trace frames
- Original values are never stored in logs or sent to AI backends
- Sanitization happens transparently without any configuration needed
Example output:
2. Text Pattern Sanitization
In addition to parameter-level sanitization, the system also masks common sensitive patterns in error messages and file paths before sending to AI:
- Authorization headers:
Authorization: Bearer token→Authorization: Bearer ***REDACTED*** - JWT tokens: Long base64 strings in JWT format →
***REDACTED*** - Email addresses:
[email protected]→***REDACTED*** - API keys and secrets:
api_key=sk-123...→api_key=***REDACTED***
3. Configuration
The default mask string is ***REDACTED***, but you can customize it programmatically if needed:
Where sanitization applies:
- AI prompts (error messages, file paths, and indirectly via stack traces)
Best practices:
- Mark all sensitive parameters with
#[SensitiveParameter]: passwords, tokens, API keys, personal data - The sanitization is automatic and requires no configuration
For more implementation details, see src/Internal/Util/SensitiveParameterSanitizer.php.
Console colors customization (CLI)
You can customize the colors used in the CLI output (syntax highlighting, severity header background, title, AI suggestions, stack trace and locations).
Two ways to configure:
- Environment variable
PHP_ERROR_INSIGHT_CONSOLE_COLORScontaining a JSON object - Programmatic via
Config::fromEnvAndArray(['consoleColors' => [...]])
Structure of the JSON/object:
Notes:
- Each style uses the form
[fg, bg, options[]].fgandbgaccept Symfony Console color names (e.g., "white", "yellow", "red", "blue", "cyan", "magenta", "gray"), andoptionscan includebold,underscore,blink,reverse,conceal. tokensoverrides the syntax highlighter palette for these categories:default,comment,string,keyword,html,variable,function,method.severitymapserror|warning|infoto a background color name for the header badge with the severity label.styleslets you tweak semantic tags used by the renderer:title(error message),suggestion(AI suggestions label and items),stack(stack trace lines when rendered in compact mode),location(file:line),gutter_hl(current line number in code excerpts),gutter_num(non-current line numbers), andgutter_sep(the vertical separator).- Any key you omit falls back to sensible defaults.
Examples
-
Via environment variable:
- Via code:
Development
This project uses several development tools to maintain code quality. Use the following composer scripts for easy access to these tools:
Code Quality Scripts
Combined Scripts
Development Workflow
- Install dependencies:
composer install - Make your changes
- Run quality checks:
composer quality - Fix issues automatically:
composer fix-all - Run tests with coverage:
composer test-coverage
The project is configured for PHP 8.1+ and includes:
- PHP CS Fixer for code style enforcement
- Rector for automated code improvements and PHP version upgrades
- PHPStan for static analysis
- PHPUnit for testing
- GitHub Actions with matrix testing for PHP versions 8.1, 8.2, 8.3, 8.4, 8.5
License
GPL-3.0-or-later
This project is licensed under the GNU General Public License v3.0 or later. See the LICENSE file for details.
All versions of php-error-insight with dependencies
symfony/var-dumper Version ^5.0|^6.0|^7.0|^8.0
ext-curl Version *
symfony/console Version ^5.0|^6.0|^7.0|^8.0
symfony/filesystem Version ^5.0|^6.0|^7.0|^8.0