-
Notifications
You must be signed in to change notification settings - Fork 99
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
IGNITE-24150 Ability to have different prefixes for exceptions #4991
Open
ygerzhedovich
wants to merge
6
commits into
apache:main
Choose a base branch
from
gridgain:ignite-24150
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4e85fa
IGNITE-24150 Ability to have different prefixes for exceptions
joooger e5a9fd8
IGNITE-24150: fixes after review
joooger d503b49
IGNITE-24150: fixes for .Net
joooger e93aea2
IGNITE-24150: fixes for .Net
joooger 3bfdf72
IGNITE-24150: fixes for .Net
joooger d6ef70d
Merge remote-tracking branch 'origin/main' into ignite-24150
joooger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -17,16 +17,33 @@ | |||
|
||||
package org.apache.ignite.lang; | ||||
|
||||
import static java.util.regex.Pattern.DOTALL; | ||||
|
||||
import java.util.HashMap; | ||||
import java.util.HashSet; | ||||
import java.util.Locale; | ||||
import java.util.Map; | ||||
import java.util.regex.Matcher; | ||||
import java.util.regex.Pattern; | ||||
import org.apache.ignite.error.code.annotations.ErrorCodeGroup; | ||||
import org.jetbrains.annotations.Nullable; | ||||
|
||||
/** | ||||
* Defines error groups and its errors. | ||||
*/ | ||||
@SuppressWarnings("PublicInnerClass") | ||||
public class ErrorGroups { | ||||
/** Additional prefix that is used in a human-readable format of ignite errors. */ | ||||
public static final String IGNITE_ERR_PREFIX = "IGN"; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps, the following code should be updated as well
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||
private static final String PLACEHOLDER = "${ERROR_PREFIX}"; | ||||
private static final String EXCEPTION_MESSAGE_STRING_PATTERN = | ||||
"(.*)(" + PLACEHOLDER + ")-([A-Z]+)-(\\d+)\\s(TraceId:)([a-f0-9]{8}(?:-[a-f0-9]{4}){4}[a-f0-9]{8})(\\s?)(.*)"; | ||||
|
||||
/** Error message pattern. */ | ||||
private static Pattern EXCEPTION_MESSAGE_PATTERN; | ||||
|
||||
private static final HashSet<String> REGISTERED_ERROR_PREFIXES = new HashSet<>(); | ||||
|
||||
/** List of all registered error groups. */ | ||||
private static final Map<Short, ErrorGroup> registeredGroups = new HashMap<>(); | ||||
|
||||
|
@@ -44,7 +61,7 @@ public static synchronized void initialize() { | |||
} | ||||
|
||||
/** | ||||
* Creates a new error group with the given {@code groupName} and {@code groupCode}. | ||||
* Creates a new error group with the given {@code groupName} and {@code groupCode} and default error prefix. | ||||
* | ||||
* @param groupName Group name to be created. | ||||
* @param groupCode Group code to be created. | ||||
|
@@ -53,6 +70,20 @@ public static synchronized void initialize() { | |||
* the given {@code groupName} is {@code null} or empty. | ||||
*/ | ||||
public static synchronized ErrorGroup registerGroup(String groupName, short groupCode) { | ||||
return registerGroup(IGNITE_ERR_PREFIX, groupName, groupCode); | ||||
} | ||||
|
||||
/** | ||||
* Creates a new error group with the given {@code groupName} and {@code groupCode}. | ||||
* | ||||
* @param errorPrefix Error prefix which should be used for the created error group. | ||||
* @param groupName Group name to be created. | ||||
* @param groupCode Group code to be created. | ||||
* @return New error group. | ||||
* @throws IllegalArgumentException If the specified name or group code already registered. Also, this exception is thrown if | ||||
* the given {@code groupName} is {@code null} or empty. | ||||
*/ | ||||
public static synchronized ErrorGroup registerGroup(String errorPrefix, String groupName, short groupCode) { | ||||
if (groupName == null || groupName.isEmpty()) { | ||||
throw new IllegalArgumentException("Group name is null or empty"); | ||||
} | ||||
|
@@ -73,13 +104,36 @@ public static synchronized ErrorGroup registerGroup(String groupName, short grou | |||
} | ||||
} | ||||
|
||||
ErrorGroup newGroup = new ErrorGroup(grpName, groupCode); | ||||
if (REGISTERED_ERROR_PREFIXES.add(errorPrefix)) { | ||||
String errorPrefixes = String.join("|", REGISTERED_ERROR_PREFIXES); | ||||
String pattern = EXCEPTION_MESSAGE_STRING_PATTERN.replace(PLACEHOLDER, errorPrefixes); | ||||
EXCEPTION_MESSAGE_PATTERN = Pattern.compile(pattern, DOTALL); | ||||
korlov42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
} | ||||
|
||||
ErrorGroup newGroup = new ErrorGroup(errorPrefix, grpName, groupCode); | ||||
|
||||
registeredGroups.put(groupCode, newGroup); | ||||
|
||||
return newGroup; | ||||
} | ||||
|
||||
/** | ||||
* Returns a message extracted from the given {@code errorMessage} if this {@code errorMessage} matches | ||||
* {@link #EXCEPTION_MESSAGE_PATTERN}. If {@code errorMessage} does not match the pattern or {@code null} then returns the original | ||||
* {@code errorMessage}. | ||||
* | ||||
* @param errorMessage Message that is returned by {@link Throwable#getMessage()} | ||||
* @return Extracted message. | ||||
*/ | ||||
public static @Nullable String extractCauseMessage(String errorMessage) { | ||||
if (errorMessage == null) { | ||||
return null; | ||||
} | ||||
|
||||
Matcher m = EXCEPTION_MESSAGE_PATTERN.matcher(errorMessage); | ||||
return (m.matches()) ? m.group(8) : errorMessage; | ||||
} | ||||
|
||||
/** | ||||
* Returns group code extracted from the given full error code. | ||||
* | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm a little confused by the name. Perhaps, it would be nice to change to
groupNamePrefix
, orvendorSpecificPrefix
etc. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we honestly it's not so important and all variants reflect nature of the field but from different perspective