Closed bflad closed 6 years ago
When implementing a large amount of messaging, it can be very helpful to be able to sort the errors before printing them out.
Previously with errors appended from looping through a map, it can return something like the following:
11 error(s) occurred: * expected SNS topic attribute "ApplicationSuccessFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "HTTPSuccessFeedbackSampleRate" to match "^80$", received: "" * expected SNS topic attribute "LambdaSuccessFeedbackSampleRate" to match "^90$", received: "" * expected SNS topic attribute "LambdaSuccessFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "SQSFailureFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "ApplicationSuccessFeedbackSampleRate" to match "^100$", received: "" * expected SNS topic attribute "ApplicationFailureFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "HTTPSuccessFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "HTTPFailureFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "LambdaFailureFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "SQSSuccessFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: ""
Now it should be possible to sort.Sort(errors) before formatting so it returns:
sort.Sort(errors)
11 error(s) occurred: * expected SNS topic attribute "ApplicationFailureFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "ApplicationSuccessFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "ApplicationSuccessFeedbackSampleRate" to match "^100$", received: "" * expected SNS topic attribute "HTTPFailureFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "HTTPSuccessFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "HTTPSuccessFeedbackSampleRate" to match "^80$", received: "" * expected SNS topic attribute "LambdaFailureFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "LambdaSuccessFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "LambdaSuccessFeedbackSampleRate" to match "^90$", received: "" * expected SNS topic attribute "SQSFailureFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: "" * expected SNS topic attribute "SQSSuccessFeedbackRoleArn" to match "^arn:aws:iam::[0-9]{12}:role/sns-delivery-status-role-", received: ""
We could take this further and implement a SortedListFormatFunc or augment the existing ListFormatFunc to automatically sort as well.
SortedListFormatFunc
ListFormatFunc
This seems reasonable to me, especially since its up to the caller to decide whether they want to sort or not so it doesn't introduce any breaking changes.
When implementing a large amount of messaging, it can be very helpful to be able to sort the errors before printing them out.
Previously with errors appended from looping through a map, it can return something like the following:
Now it should be possible to
sort.Sort(errors)
before formatting so it returns:We could take this further and implement a
SortedListFormatFunc
or augment the existingListFormatFunc
to automatically sort as well.