Skip to content

Commit

Permalink
fix/failure details (#492)
Browse files Browse the repository at this point in the history
* fix how failures are handled in grpc

* fix lint
  • Loading branch information
just-at-uber authored Jul 19, 2022
1 parent 3c6aae9 commit 3b3ed87
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2022 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const atob = require('atob');

const formatFailureDetails = failure => {
if (!failure?.details) {
return null;
}

const decodedFailureDetails = atob(failure.details);

try {
return JSON.parse(decodedFailureDetails);
} catch (e) {
return decodedFailureDetails;
}
};

module.exports = formatFailureDetails;
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const formatFailureDetails = require('../format-failure-details');

const formatActivityTaskFailedEventAttributes = ({
failure,
scheduledEventId,
startedEventId,
...eventAttributes
}) => ({
...eventAttributes,
details: failure?.details || null,
details: formatFailureDetails(failure),
reason: failure?.reason || '',
scheduledEventId: parseInt(scheduledEventId),
startedEventId: parseInt(startedEventId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const formatFailureDetails = require('../format-failure-details');

const formatActivityTaskStartedEventAttributes = ({
lastFailure,
scheduledEventId,
...eventAttributes
}) => ({
...eventAttributes,
lastFailureDetails: lastFailure?.details || null,
lastFailureDetails: formatFailureDetails(lastFailure),
lastFailureReason: lastFailure?.reason || '',
scheduledEventId: parseInt(scheduledEventId),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const formatFailureDetails = require('../format-failure-details');
const formatPayload = require('../format-payload');

const formatActivityTaskTimedOutEventAttributes = ({
Expand All @@ -30,7 +31,7 @@ const formatActivityTaskTimedOutEventAttributes = ({
}) => ({
...eventAttributes,
details: formatPayload(details),
lastFailureDetails: lastFailure?.details || null,
lastFailureDetails: formatFailureDetails(lastFailure),
lastFailureReason: lastFailure?.reason || '',
scheduledEventId: parseInt(scheduledEventId),
startedEventId: parseInt(startedEventId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const formatFailureDetails = require('../format-failure-details');

const formatChildWorkflowExecutionFailedEventAttributes = ({
failure,
initiatedEventId,
startedEventId,
...eventAttributes
}) => ({
...eventAttributes,
details: failure?.details || null,
details: formatFailureDetails(failure),
initiatedEventId: parseInt(initiatedEventId),
reason: failure?.reason || '',
startedEventId: parseInt(startedEventId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const formatFailureDetails = require('../format-failure-details');

const formatDecisionTaskFailedEventAttributes = ({
failure,
forkEventVersion,
Expand All @@ -27,7 +29,7 @@ const formatDecisionTaskFailedEventAttributes = ({
...eventAttributes
}) => ({
...eventAttributes,
details: failure?.details || null,
details: formatFailureDetails(failure),
forkEventVersion: parseInt(forkEventVersion),
reason: failure?.reason || '',
scheduledEventId: parseInt(scheduledEventId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// THE SOFTWARE.

const formatEnum = require('../format-enum');
const formatFailureDetails = require('../format-failure-details');
const formatPayload = require('../format-payload');
const formatPayloadMap = require('../format-payload-map');
const formatDurationToSeconds = require('../format-duration-to-seconds');
Expand All @@ -44,7 +45,7 @@ const formatWorkflowExecutionContinuedAsNewEventAttributes = ({
executionStartToCloseTimeoutSeconds: formatDurationToSeconds(
executionStartToCloseTimeout
),
failureDetails: failure?.details || null,
failureDetails: formatFailureDetails(failure),
failureReason: failure?.reason || '',
header: formatPayloadMap(header, 'fields'),
initiator: formatEnum(initiator, 'CONTINUE_AS_NEW_INITIATOR'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const formatFailureDetails = require('../format-failure-details');

const formatWorkflowExecutionFailedEventAttributes = ({
failure,
decisionTaskCompletedEventId,
}) => ({
decisionTaskCompletedEventId: parseInt(decisionTaskCompletedEventId),
details: failure?.details || null,
details: formatFailureDetails(failure),
reason: failure?.reason || '',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// THE SOFTWARE.

const formatEnum = require('../format-enum');
const formatFailureDetails = require('../format-failure-details');
const formatPayload = require('../format-payload');
const formatPayloadMap = require('../format-payload-map');
const formatTimestampToDatetime = require('../format-timestamp-to-datetime');
Expand Down Expand Up @@ -63,7 +64,7 @@ const formatWorkflowExecutionStartedEventAttributes = ({
),
attempt: attempt || null,
continuedExecutionRunId: continuedExecutionRunId || null,
continuedFailureDetails: continuedFailure?.details || null,
continuedFailureDetails: formatFailureDetails(continuedFailure),
continuedFailureReason: continuedFailure?.reason || null,
cronSchedule: cronSchedule || null,
expirationTimestamp: formatTimestampToDatetime(expirationTime),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// THE SOFTWARE.

const formatEnum = require('./format-enum');
const formatFailureDetails = require('./format-failure-details');
const formatTimestampToDatetime = require('./format-timestamp-to-datetime');
const formatDurationToSeconds = require('./format-duration-to-seconds');

Expand Down Expand Up @@ -65,7 +66,7 @@ const formatResponseDescribeWorkflow = ({
...pendingActivity,
activityID: parseInt(activityId),
expirationTimestamp: formatTimestampToDatetime(expirationTime),
lastFailureDetails: lastFailure?.details || null,
lastFailureDetails: formatFailureDetails(lastFailure),
lastFailureReason: lastFailure?.reason || null,
lastHeartbeatTimestamp: formatTimestampToDatetime(lastHeartbeatTime),
lastStartedTimestamp: formatTimestampToDatetime(lastStartedTime),
Expand Down

0 comments on commit 3b3ed87

Please sign in to comment.