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

Implement advanced java exception handling using liblognorm error callback #18

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Tiihott
Copy link
Contributor

@Tiihott Tiihott commented Jan 28, 2025

Includes:

Also includes commits from PR #14. Rebase may be needed in this PR after they have been merged to main.
New commits are cf2b6e6 and later.

@Tiihott Tiihott requested a review from 51-code January 28, 2025 11:23
@Tiihott Tiihott self-assigned this Jan 28, 2025
Copy link

@51-code 51-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments about tests.

@Tiihott Tiihott requested a review from 51-code January 29, 2025 08:09
Copy link

@51-code 51-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Tiihott
Copy link
Contributor Author

Tiihott commented Jan 29, 2025

Noticed an error in liblognorm documentations on how the pure json format should be constructed.
Remade json sample rulebases with the proper format on commit 23d2d2c

@Tiihott Tiihott requested a review from 51-code January 29, 2025 13:35
Copy link

@51-code 51-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New changes look good.

@Tiihott
Copy link
Contributor Author

Tiihott commented Feb 17, 2025

Rebased to main

@Tiihott
Copy link
Contributor Author

Tiihott commented Feb 17, 2025

Added exception test for partially invalid rulebase.

@Tiihott
Copy link
Contributor Author

Tiihott commented Feb 21, 2025

Rebased to main


@Override
public void invoke(Pointer cookie, String msg, int length) {
LOGGER.debug("liblognorm: {}", msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use "<{}>", msg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in commit 9e0e25d

@Override
public void invoke(Pointer cookie, String msg, int length) {
errors.add(msg);
LOGGER.error("liblognorm error: {}", msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use "<{}>", msg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in commit 9e0e25d

* Method for throwing any received liblognorm error messages as java exception.
*/
public void throwOccurredErrors() {
if (!errors.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should thrown errors be cleared or are they always so fatal that the object instance is invalid after some occured?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rulebase loading method for liblognorm will not return error codes when the rulebase has errors in it, instead it will generate error messages and return 0 indicating that the loading of the rulebase was successful.
By implementing the check for error messages those rulebase errors can be caught as java exceptions.

In my opinion the errors should be handled using fail fast, making the object instance invalid if they occur.

@Tiihott Tiihott requested a review from kortemik February 24, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement advanced java exception handling for liblognorm ln_loadSamples() method
3 participants