Skip to content

Commit bc6d0d6

Browse files
Update write_first_app tutorial (#5336)
The Fabric Gateway client API v1.10.0 provides some ease-of-use enhancements to make error details returned from the peer more accessible for Go client applications. This change updates the tutorial content to reflect the simplified client-side code and improved output. Signed-off-by: Mark S. Lewis <[email protected]>
1 parent d9a329c commit bc6d0d6

File tree

1 file changed

+33
-46
lines changed

1 file changed

+33
-46
lines changed

docs/source/write_first_app.rst

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Running a Fabric Application
22
############################
33
.. note:: If you're not yet familiar with the fundamental architecture of a Fabric blockchain network, you may want to
44
visit the :doc:`key_concepts` section prior to continuing.
5-
5+
66
You should also be familiar with the Fabric Gateway service and how it relates to the application transaction
77
flow, documented in the :doc:`gateway` section.
88

@@ -305,14 +305,14 @@ override gRPC option is specified to force this endpoint address to be interpret
305305
'grpc.ssl_target_name_override': peerHostOverride,
306306
});
307307
}
308-
308+
309309
.. code-tab:: go Go
310310

311311
const (
312312
peerEndpoint = "dns:///localhost:7051"
313313
peerHostOverride = "peer0.org1.example.com"
314314
)
315-
315+
316316
func newGrpcConnection() *grpc.ClientConn {
317317
certificatePEM, err := os.ReadFile(tlsCertPath)
318318
if err != nil {
@@ -390,7 +390,7 @@ based on that user's private key.
390390
const privateKey = crypto.createPrivateKey(privateKeyPem);
391391
return signers.newPrivateKeySigner(privateKey);
392392
}
393-
393+
394394
.. code-tab:: go Go
395395

396396
clientConnection := newGrpcConnection()
@@ -440,7 +440,7 @@ based on that user's private key.
440440

441441
return sign
442442
}
443-
443+
444444
.. code-tab:: java Java
445445

446446
var channel = newGrpcConnection();
@@ -677,14 +677,14 @@ Sample application ``CreateAsset`` call:
677677
.. note:: In the application snippets above, it is important to note that the ``CreateAsset`` transaction is submitted
678678
with the same type and number of arguments the chaincode is expecting, and in the correct sequence. In this
679679
case the correctly sequenced arguments are:
680-
680+
681681
.. code-block:: text
682-
682+
683683
assetId, "yellow", "5", "Tom", "1300"
684-
684+
685685
The corresponding smart contract's ``CreateAsset`` transaction function is expecting the following sequence
686686
of arguments that define the asset object:
687-
687+
688688
.. code-block:: text
689689
690690
ID, Color, Size, Owner, AppraisedValue
@@ -852,39 +852,21 @@ Sample application failing ``UpdateAsset`` call:
852852

853853
fmt.Println("*** Successfully caught the error:")
854854
855-
var endorseErr *client.EndorseError
856-
var submitErr *client.SubmitError
857855
var commitStatusErr *client.CommitStatusError
858-
var commitErr *client.CommitError
859-
860-
if errors.As(err, &endorseErr) {
861-
fmt.Printf("Endorse error for transaction %s with gRPC status %v: %s\n", endorseErr.TransactionID, status.Code(endorseErr), endorseErr)
862-
} else if errors.As(err, &submitErr) {
863-
fmt.Printf("Submit error for transaction %s with gRPC status %v: %s\n", submitErr.TransactionID, status.Code(submitErr), submitErr)
864-
} else if errors.As(err, &commitStatusErr) {
865-
if errors.Is(err, context.DeadlineExceeded) {
866-
fmt.Printf("Timeout waiting for transaction %s commit status: %s", commitStatusErr.TransactionID, commitStatusErr)
867-
} else {
868-
fmt.Printf("Error obtaining commit status for transaction %s with gRPC status %v: %s\n", commitStatusErr.TransactionID, status.Code(commitStatusErr), commitStatusErr)
869-
}
870-
} else if errors.As(err, &commitErr) {
871-
fmt.Printf("Transaction %s failed to commit with status %d: %s\n", commitErr.TransactionID, int32(commitErr.Code), err)
872-
} else {
873-
panic(fmt.Errorf("unexpected error type %T: %w", err, err))
874-
}
875-
876-
statusErr := status.Convert(err)
877-
878-
details := statusErr.Details()
879-
if len(details) > 0 {
880-
fmt.Println("Error Details:")
856+
var transactionErr *client.TransactionError
881857
882-
for _, detail := range details {
883-
switch detail := detail.(type) {
884-
case *gateway.ErrorDetail:
885-
fmt.Printf("- address: %s; mspId: %s; message: %s\n", detail.Address, detail.MspId, detail.Message)
886-
}
887-
}
858+
if errors.As(err, &commitStatusErr) {
859+
if errors.Is(err, context.DeadlineExceeded) {
860+
fmt.Printf("Timeout waiting for transaction %s commit status: %s\n", commitStatusErr.TransactionID, commitStatusErr)
861+
} else {
862+
fmt.Printf("Error obtaining commit status for transaction %s with gRPC status %v: %s\n", commitStatusErr.TransactionID, status.Code(commitStatusErr), commitStatusErr)
863+
}
864+
} else if errors.As(err, &transactionErr) {
865+
// The error could be an EndorseError, SubmitError or CommitError.
866+
fmt.Println(err)
867+
fmt.Printf("TransactionID: %s\n", transactionErr.TransactionID)
868+
} else {
869+
panic(fmt.Errorf("unexpected error type %T: %w", err, err))
888870
}
889871

890872
.. code-tab:: java Java
@@ -909,7 +891,7 @@ Terminal Output (with stack traces removed for clarity):
909891

910892
.. code-tab:: text TypeScript
911893

912-
*** Successfully caught the error:
894+
*** Successfully caught the error:
913895
EndorseError: 10 ABORTED: failed to endorse transaction, see attached details for more info
914896
at ... {
915897
code: 10,
@@ -932,9 +914,12 @@ Terminal Output (with stack traces removed for clarity):
932914
.. code-tab:: text Go
933915

934916
*** Successfully caught the error:
935-
Endorse error for transaction 0a0bf1af9c53e0621d6dc98217fb882e0c6d5e174dc1a45f5cb4e07580528347 with gRPC status Aborted: rpc error: code = Aborted desc = failed to endorse transaction, see attached details for more info
936-
Error Details:
937-
- address: peer0.org1.example.com:7051; mspId: Org1MSP; message: chaincode response 500, the asset asset70 does not exist
917+
endorse error: rpc error: code = Aborted desc = failed to endorse transaction, see attached details for more info
918+
Details:
919+
- Address: peer0.org1.example.com:7051
920+
MspId: Org1MSP
921+
Message: chaincode response 500, the asset asset70 does not exist
922+
TransactionID: 1cdfe852b0f32b30049f45d7f83d17761b329f6ceba87be0fc9a7dd5966fbf17
938923
939924
.. code-tab:: text Java
940925

@@ -944,8 +929,10 @@ Terminal Output (with stack traces removed for clarity):
944929
Caused by: io.grpc.StatusRuntimeException: ABORTED: failed to endorse transaction, see attached details for more info
945930
at ...
946931
Error details:
947-
address: peer0.org1.example.com:7051; mspId: Org1MSP; message: chaincode response 500, the asset asset70 does not exist
948-
Transaction ID: 5dcc3576cbb851bfbd998f2413da7707761ad15911b7c7fba853e72ac1b3b002
932+
- address: peer0.org1.example.com:7051
933+
mspId: Org1MSP
934+
message: chaincode response 500, the asset asset70 does not exist
935+
Transaction ID: bb7e55f0790cd518d894c84d4f5b6757d247f99281a6fdb197fd8c65154c009b
949936
950937
The ``Endorse`` error type indicates that failure occurred during endorsement, and the
951938
`gRPC status code <https://grpc.github.io/grpc/core/md_doc_statuscodes.html>`_ of ``ABORTED`` indicates that the

0 commit comments

Comments
 (0)