Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit c13c937

Browse files
d1vyanktroyronda
authored andcommitted
[FAB-9849] Document status, multi, retry packages
Change-Id: I8c2d83022ed223b675f4a9f95992c1a6ba74481e Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
1 parent 0404e72 commit c13c937

File tree

5 files changed

+78
-1
lines changed

5 files changed

+78
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package multi
8+
9+
import (
10+
"fmt"
11+
)
12+
13+
func Example() {
14+
errs := Errors{}
15+
errs = append(errs, fmt.Errorf("peer0 failed"))
16+
errs = append(errs, fmt.Errorf("peer1 failed"))
17+
18+
// Multi errors implement the standard error interface and are returned as regular errors
19+
err := interface{}(errs).(error)
20+
21+
// We can extract multi errors from a standard error
22+
errs, ok := err.(Errors)
23+
fmt.Println(ok)
24+
25+
// And handle each error individually
26+
for _, e := range errs {
27+
fmt.Println(e)
28+
}
29+
30+
// Output:
31+
// true
32+
// peer0 failed
33+
// peer1 failed
34+
}

pkg/common/errors/multi/multi.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
// Package multi is an error type that holds multiple errors. These errors
8+
// typically originate from operations that target multiple nodes.
9+
// For example, a transaction proposal with two endorsers could return
10+
// a multi error type if both endorsers return errors
711
package multi
812

913
import (

pkg/common/errors/retry/retry.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
// Package retry provides retransmission capabilities to fabric-sdk-go
7+
// Package retry provides retransmission capabilities to fabric-sdk-go.
8+
// The only user interaction with this package is expected to be with the
9+
// defaults defined below.
10+
// They can be used in conjunction with the WithRetry setting offered by certain
11+
// clients in the SDK:
12+
// https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/client/channel#WithRetry
13+
// https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt#WithRetry
814
package retry
915

1016
import (
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package status
8+
9+
import "fmt"
10+
11+
func Example() {
12+
// Status errors are returned for certain transient errors by clients in the SDK
13+
statusError := New(ClientStatus, EndorsementMismatch.ToInt32(), "proposal responses do not match", nil)
14+
15+
// Status errors implement the standard error interface and are returned as regular errors
16+
err := interface{}(statusError).(error)
17+
18+
// A user can extract status information from a status
19+
status, ok := FromError(err)
20+
fmt.Println(ok)
21+
fmt.Println(status.Group)
22+
fmt.Println(Code(status.Code))
23+
fmt.Println(status.Message)
24+
25+
// Output:
26+
// true
27+
// Client Status
28+
// ENDORSEMENT_MISMATCH
29+
// proposal responses do not match
30+
}

pkg/common/errors/status/status.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ SPDX-License-Identifier: Apache-2.0
77
// Package status defines metadata for errors returned by fabric-sdk-go. This
88
// information may be used by SDK users to make decisions about how to handle
99
// certain error conditions.
10+
// Status codes are divided by group, where each group represents a particular
11+
// component and the codes correspond to those returned by the component.
12+
// These are defined in detail below.
1013
package status
1114

1215
import (

0 commit comments

Comments
 (0)