Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handling errors in ProcessWire Custom Page Classes #515

Open
klor opened this issue Jan 6, 2024 · 2 comments
Open

Gracefully handling errors in ProcessWire Custom Page Classes #515

klor opened this issue Jan 6, 2024 · 2 comments

Comments

@klor
Copy link

klor commented Jan 6, 2024

Short description of the enhancement

Enhance error handling mechanisms in ProcessWire's custom page classes to degrade gracefully and provide comprehensive, developer-friendly error messages.

Optional: Steps that explain the enhancement

  1. Integrate a sophisticated error detection system within the custom page class architecture that identifies and catches common PHP errors.
  2. Ensure the system degrades gracefully by providing detailed, contextual error messages that assist in debugging without exposing sensitive system details.
  3. Enhance the development experience by optionally allowing more verbose error reporting in development environments while ensuring minimal impact in production.

Current vs. suggested behavior

Currently, errors in custom page classes result in a stark Server Error 500 with no helpful output for debugging. The suggested behavior is for ProcessWire to gracefully degrade by catching these errors and providing a useful error message that includes specifics about the nature and location of the error, thereby aiding in a quick resolution.

Code example that currently results in error 500:

<?php namespace ProcessWire;
class FooPage extends Page {
	public function my_func() {
		$a = 1  // missing semi-colon causes error 500
	}
}

Why would the enhancement be useful to users?

Implementing a graceful degradation process for errors in custom page classes would make the development process with ProcessWire much more efficient and less frustrating. Developers would spend less time deciphering the cause of generic server errors and more time on productive development, improving both the developer experience and the stability of applications built with ProcessWire.

@Toutouwai
Copy link

Toutouwai commented Jan 6, 2024

PW doesn't need to reinvent the wheel and become a PHP debugger when we have an excellent debugging tool created by @adrianbj that's specifically tailored to the PW environment and provides all the things you're requesting and much more.

2024-01-07_100157

@ryancramerdesign
Copy link
Member

@klor Any classes, whether custom Page classes, modules, or anything should will behave the same with regards to errors, as they all are handled by PW's error handler. If you want verbose errors you need to have debug mode enabled by setting $config->debug=true; in your /site/config.php file. When enabled, an error in a custom Page class (or anything else) will output the file name, line number, and error message. When you don't have debug mode enabled, PW intentionally hides any details about the error for security purposes, returning only a 500 response and instead logging the error. Like Toutouwai mentioned above, using TracyDebugger will provide even more detail, which is useful in a local development environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants