-
Notifications
You must be signed in to change notification settings - Fork 213
Add application err category #2485
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
Changes from 10 commits
4fd8dd9
71c11a4
1858f95
4e8a98e
433c066
6875557
29ff5dc
44de349
a64f646
d22a2ad
823848e
ab0a99a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||
| /* | ||||||
| * Copyright (C) 2024 Temporal Technologies, Inc. All Rights Reserved. | ||||||
| * | ||||||
| * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||||||
| * | ||||||
| * Modifications copyright (C) 2017 Uber Technologies, Inc. | ||||||
| * | ||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| * you may not use this material except in compliance with the License. | ||||||
| * You may obtain a copy of the License at | ||||||
| * | ||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| * | ||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| * See the License for the specific language governing permissions and | ||||||
| * limitations under the License. | ||||||
| */ | ||||||
|
|
||||||
| package io.temporal.failure; | ||||||
|
|
||||||
| /** | ||||||
| * Mirrors the proto definition for ApplicationErrorCategory. Used to categorize application | ||||||
|
Contributor
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.
Suggested change
I don't think we need to mention the proto def. here the docs are for the end user and that isn't really relevant for them
Contributor
Author
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 |
||||||
| * failures, for example, to distinguish benign errors from others. | ||||||
| * | ||||||
| * @see io.temporal.api.enums.v1.ApplicationErrorCategory | ||||||
| */ | ||||||
| public enum ApplicationErrorCategory { | ||||||
| UNSPECIFIED, | ||||||
| /** Expected application error with little/no severity. */ | ||||||
| BENIGN, | ||||||
| ; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
| * | ||
| * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this material except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.temporal.internal.common; | ||
|
|
||
| import io.temporal.api.failure.v1.Failure; | ||
| import io.temporal.failure.ApplicationErrorCategory; | ||
| import io.temporal.failure.ApplicationFailure; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public class FailureUtils { | ||
|
Contributor
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. Pedantic, but would add a private constructor here |
||
| private FailureUtils() {} | ||
|
|
||
| public static boolean isBenignApplicationFailure(@Nullable Throwable t) { | ||
| if (t instanceof ApplicationFailure | ||
| && ((ApplicationFailure) t).getApplicationErrorCategory() | ||
| == ApplicationErrorCategory.BENIGN) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public static boolean isBenignApplicationFailure(@Nullable Failure failure) { | ||
| if (failure != null | ||
| && failure.getApplicationFailureInfo() != null | ||
| && FailureUtils.categoryFromProto(failure.getApplicationFailureInfo().getCategory()) | ||
| == ApplicationErrorCategory.BENIGN) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public static ApplicationErrorCategory categoryFromProto( | ||
| io.temporal.api.enums.v1.ApplicationErrorCategory protoCategory) { | ||
| if (protoCategory == null) { | ||
| return ApplicationErrorCategory.UNSPECIFIED; | ||
| } | ||
| switch (protoCategory) { | ||
| case APPLICATION_ERROR_CATEGORY_BENIGN: | ||
| return ApplicationErrorCategory.BENIGN; | ||
| case APPLICATION_ERROR_CATEGORY_UNSPECIFIED: | ||
| case UNRECOGNIZED: | ||
| default: | ||
| // Fallback unrecognized or unspecified proto values as UNSPECIFIED | ||
| return ApplicationErrorCategory.UNSPECIFIED; | ||
| } | ||
| } | ||
|
|
||
| public static io.temporal.api.enums.v1.ApplicationErrorCategory categoryToProto( | ||
| io.temporal.failure.ApplicationErrorCategory category) { | ||
| switch (category) { | ||
| case BENIGN: | ||
| return io.temporal.api.enums.v1.ApplicationErrorCategory.APPLICATION_ERROR_CATEGORY_BENIGN; | ||
| case UNSPECIFIED: | ||
| default: | ||
| // Fallback to UNSPECIFIED for unknown values | ||
| return io.temporal.api.enums.v1.ApplicationErrorCategory | ||
| .APPLICATION_ERROR_CATEGORY_UNSPECIFIED; | ||
| } | ||
| } | ||
| } | ||
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.
It seems in other parts of the SDK, e.g. parent close policy, we just expose the raw enum from proto. Should we do the same here? It has "unrecognized", automatically gets new values, etc.
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.
Didn't notice that, have changed to use raw proto