aws / aws-swf-flow-library

AWS Simple Workflow Flow framework library
Apache License 2.0
61 stars 54 forks source link

POJOActivityImplementation should not throw ActivityFailureException with details larger than 32k #28

Open redparham opened 4 years ago

redparham commented 4 years ago

POJOActivityImplementation.throwActivityFailureException method throws ActivityFailureExceptions but doesn't truncate the "details" constructor param to 32k. This causes AmazonSimpleWorkflowClient.executeRespondActivityTaskFailed to fail:

Caused by: com.amazonaws.services.simpleworkflow.model.AmazonSimpleWorkflowException: 1 validation error detected: Value '...some error payload >32k...' at 'details' failed to satisfy constraint: Member must have length less than or equal to 32768 (Service: AmazonSimpleWorkflow; Status Code: 400; Error Code: ValidationException; Request ID: 741c57e6-e861-42f4-be70-3ab0d1f75761)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1712)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1367)
...
at com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflowClient.respondActivityTaskFailed(AmazonSimpleWorkflowClient.java:3115)
...
at com.amazonaws.services.simpleworkflow.flow.worker.SynchronousActivityTaskPoller.execute(SynchronousActivityTaskPoller.java:211)
...

Notice that the 'reason' parameter is truncated - but not the details param: com.amazonaws.services.simpleworkflow.flow.pojo.POJOActivityImplementation

void throwActivityFailureException(Throwable exception) 
            throws ActivityFailureException, CancellationException {

        if (exception instanceof CancellationException) {
            throw (CancellationException)exception;
        }

        String reason = WorkflowExecutionUtils.truncateReason(exception.getMessage());
        String details = null;
        try {
            details = converter.toData(exception);
        } catch (DataConverterException dataConverterException) {
            if (dataConverterException.getCause() == null) {
                dataConverterException.initCause(exception);
            }
            throw dataConverterException;
        }

        throw new ActivityFailureException(reason, details);
    }

I suggest truncating 'details' the same way as 'reason': details = WorkflowExecutionUtils.truncateDetails(converter.toData(exception));

Feel free to assign this to me to fix by pull request... thanks.