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

refactor: restrict webforj to one app and unfiy error handling #726

Merged
merged 4 commits into from
Sep 10, 2024
Merged

Conversation

hyyan
Copy link
Member

@hyyan hyyan commented Sep 8, 2024

The (PR) enforces a single application limit in webforJ and shifts all error handling responsibilities to the Java side, giving developers full control over error management.

Application Discovery Rules:

  1. During the webforJ bootstrap process, all classes that extend com.webforj.App are scanned. If multiple applications are found, the system looks for the com.webforj.annotation.AppEntry annotation. If any of the discovered classes are annotated with @AppEntry, the first one encountered is considered the entry point.

    • If a class is annotated with @AppEntry, that class is selected as the entry point.
    • If multiple classes are annotated with @AppEntry, an exception is thrown, listing all the discovered classes.
    • If no class is annotated and only one subclass of App is found, that class is selected as the entry point.
    • If no class is annotated and multiple subclasses of App are found, an exception is thrown, detailing each subclass.

Error Handling

webforJ will capture all errors during the application lifecycle and forward them to the appropriate error handler through the ErrorHandler interface.

Applications can implement this interface to manage specific exceptions. The implementing class should be named after the exception it handles, followed by the suffix ErrorHandler. it must be registered in the com.webforj.error.ErrorHandler placed in the META-INF/services directory. For example, to handle a java.lang.NullPointerException, the class should be named NullPointerExceptionErrorHandler, registered in com.webforj.error.ErrorHandler which is placed in META-INF/services directory.

If no error handler is found, webforJ will use its own global error handler. The default error handler will:

  1. Log the exception to the BBj debug log.
  2. Log the exception to the browser console if debug mode is enabled.
  3. Create and display an exception page if debug mode is enabled; otherwise, it will fall back to a generic error page.
ex-1 ex-2 ex-3 ex-4

@hyyan hyyan added Type: Refactor This issue requires refactoring and might introduce a breaking change Breaking Change The change includes a breaking change labels Sep 8, 2024
@hyyan hyyan added this to the 24.12 milestone Sep 8, 2024
@github-actions github-actions bot added module: foundation The change is in the foundation module BBj The issue or PR is related to the webforj BBj bootstrap and helper programs labels Sep 8, 2024
Copy link
Contributor

github-actions bot commented Sep 8, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

Copy link
Contributor

github-actions bot commented Sep 8, 2024

Code Coverage

Overall Project 68.84% -0.61% 🍏
Files changed 15.42%

Module Coverage
webforj-foundation 65.92% -0.9%
Files
Module File Coverage
webforj-foundation Environment.java 44.05% -11.9% 🍏
App.java 34.81% -3.87%
GlobalErrorHandler.java 10.34% -89.66%
StackTracePageBuilder.java 0%
ErrorHandler.java 0%
Bootstrap.java 0%

Copy link

sonarcloud bot commented Sep 9, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BBj The issue or PR is related to the webforj BBj bootstrap and helper programs Breaking Change The change includes a breaking change module: foundation The change is in the foundation module Type: Refactor This issue requires refactoring and might introduce a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant