forked from couchbase/gocb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GOCBC-1040: Include error causes when doing serialization
Motivation ---------- When we serialize our error types we omit the underlying "inner" error from the serialized data. We should include this information in the serialized data. Changes ------- Add custom MarshalJSON functions to our error types and convert the errors to anonymous structs so that we can stringify the "inner" error before marshalling the error. Change-Id: I80ccf1dbb2b3abb902d5a1e040211b8122f98b9e Reviewed-on: http://review.couchbase.org/c/gocb/+/144857 Reviewed-by: Brett Lawson <brett19@gmail.com> Tested-by: Charles Dixon <chvckd@gmail.com>
- Loading branch information
Showing
12 changed files
with
527 additions
and
10 deletions.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package gocb | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
func (suite *UnitTestSuite) TestAnalyticsError() { | ||
aErr := AnalyticsError{ | ||
InnerError: ErrDatasetNotFound, | ||
Statement: "select * from dataset", | ||
ClientContextID: "12345", | ||
Errors: []AnalyticsErrorDesc{{ | ||
Code: 1000, | ||
Message: "error 1000", | ||
}}, | ||
Endpoint: "http://127.0.0.1:8095", | ||
RetryReasons: []RetryReason{AnalyticsTemporaryFailureRetryReason}, | ||
RetryAttempts: 3, | ||
} | ||
|
||
b, err := json.Marshal(aErr) | ||
suite.Require().Nil(err) | ||
|
||
suite.Assert().Equal( | ||
[]byte("{\"msg\":\"dataset not found\",\"statement\":\"select * from dataset\",\"client_context_id\":\"12345\",\"errors\":[{\"Code\":1000,\"Message\":\"error 1000\"}],\"endpoint\":\"http://127.0.0.1:8095\",\"retry_reasons\":[\"ANALYTICS_TEMPORARY_FAILURE\"],\"retry_attempts\":3}"), | ||
b, | ||
) | ||
suite.Assert().Equal( | ||
"dataset not found | {\"statement\":\"select * from dataset\",\"client_context_id\":\"12345\",\"errors\":[{\"Code\":1000,\"Message\":\"error 1000\"}],\"endpoint\":\"http://127.0.0.1:8095\",\"retry_reasons\":[\"ANALYTICS_TEMPORARY_FAILURE\"],\"retry_attempts\":3}", | ||
aErr.Error(), | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package gocb | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
func (suite *UnitTestSuite) TestHTTPError() { | ||
aErr := HTTPError{ | ||
InnerError: errors.New("uh oh"), | ||
Endpoint: "http://127.0.0.1:8091", | ||
UniqueID: "123445", | ||
RetryReasons: nil, | ||
RetryAttempts: 0, | ||
} | ||
|
||
b, err := json.Marshal(aErr) | ||
suite.Require().Nil(err) | ||
|
||
fmt.Println(string(b)) | ||
suite.Assert().Equal( | ||
[]byte("{\"msg\":\"uh oh\",\"unique_id\":\"123445\",\"endpoint\":\"http://127.0.0.1:8091\"}"), | ||
b, | ||
) | ||
suite.Assert().Equal( | ||
"uh oh | {\"unique_id\":\"123445\",\"endpoint\":\"http://127.0.0.1:8091\"}", | ||
aErr.Error(), | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gocb | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/couchbase/gocbcore/v9/memd" | ||
) | ||
|
||
func (suite *UnitTestSuite) TestKeyValueError() { | ||
aErr := KeyValueError{ | ||
InnerError: ErrPathNotFound, | ||
StatusCode: memd.StatusBusy, | ||
DocumentID: "key", | ||
BucketName: "bucket", | ||
ScopeName: "scope", | ||
CollectionName: "collection", | ||
CollectionID: 9, | ||
ErrorName: "barry", | ||
ErrorDescription: "sheen", | ||
Opaque: 0xa1, | ||
RetryReasons: []RetryReason{CircuitBreakerOpenRetryReason}, | ||
RetryAttempts: 3, | ||
LastDispatchedTo: "10.112.210.101", | ||
LastDispatchedFrom: "10.112.210.1", | ||
LastConnectionID: "123456", | ||
} | ||
|
||
b, err := json.Marshal(aErr) | ||
suite.Require().Nil(err) | ||
|
||
suite.Assert().Equal( | ||
[]byte("{\"msg\":\"path not found\",\"status_code\":133,\"document_id\":\"key\",\"bucket\":\"bucket\",\"scope\":\"scope\",\"collection\":\"collection\",\"collection_id\":9,\"error_name\":\"barry\",\"error_description\":\"sheen\",\"opaque\":161,\"retry_reasons\":[\"CIRCUIT_BREAKER_OPEN\"],\"retry_attempts\":3,\"last_dispatched_to\":\"10.112.210.101\",\"last_dispatched_from\":\"10.112.210.1\",\"last_connection_id\":\"123456\"}"), | ||
b, | ||
) | ||
suite.Assert().Equal( | ||
"path not found | {\"status_code\":133,\"document_id\":\"key\",\"bucket\":\"bucket\",\"scope\":\"scope\",\"collection\":\"collection\",\"collection_id\":9,\"error_name\":\"barry\",\"error_description\":\"sheen\",\"opaque\":161,\"retry_reasons\":[\"CIRCUIT_BREAKER_OPEN\"],\"retry_attempts\":3,\"last_dispatched_to\":\"10.112.210.101\",\"last_dispatched_from\":\"10.112.210.1\",\"last_connection_id\":\"123456\"}", | ||
aErr.Error(), | ||
) | ||
} |
Oops, something went wrong.