Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the new google-cloud-universalledger client library, including GAPIC-generated client code, gRPC/REST transports, types, documentation, and samples. During the review, a recurring bug was identified in the REST transport (rest.py) across several methods: the response logging blocks incorrectly attempt to serialize the raw requests.Response object instead of the parsed protobuf message, which causes serialization to fail and always log the payload as None. Additionally, the reviewer recommended replacing bare except: clauses with except Exception: to comply with PEP 8 guidelines.
| try: | ||
| response_payload = universalledger.Endpoint.to_json(response) | ||
| except: | ||
| response_payload = None |
There was a problem hiding this comment.
In the REST transport, the response payload logging attempts to serialize the requests.Response object (response) instead of the parsed protobuf message instance (resp). This will always raise an exception and result in response_payload being None. It should serialize resp instead. Additionally, catching all exceptions with a bare except: should be avoided; use except Exception: instead.
| try: | |
| response_payload = universalledger.Endpoint.to_json(response) | |
| except: | |
| response_payload = None | |
| try: | |
| response_payload = universalledger.Endpoint.to_json(resp) | |
| except Exception: | |
| response_payload = None |
References
- PEP 8 recommends avoiding bare except clauses because they catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. (link)
- For telemetry and observability logging, use broad exception handling (e.g.,
except Exception: pass) to ensure a fail-open contract where telemetry failures do not disrupt the main application flow or pollute user logs with warnings.
| ) | ||
| except: | ||
| response_payload = None | ||
| http_response = { | ||
| "payload": response_payload, | ||
| "headers": dict(response.headers), |
There was a problem hiding this comment.
In the REST transport, the response payload logging attempts to serialize the requests.Response object (response) instead of the parsed protobuf message instance (resp). This will always raise an exception and result in response_payload being None. It should serialize resp instead. Additionally, catching all exceptions with a bare except: should be avoided; use except Exception: instead.
try:
response_payload = universalledger.ListEndpointsResponse.to_json(
resp
)
except Exception:
response_payload = NoneReferences
- PEP 8 recommends avoiding bare except clauses because they catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. (link)
- For telemetry and observability logging, use broad exception handling (e.g.,
except Exception: pass) to ensure a fail-open contract where telemetry failures do not disrupt the main application flow or pollute user logs with warnings.
| response | ||
| ) | ||
| except: | ||
| response_payload = None | ||
| http_response = { | ||
| "payload": response_payload, |
There was a problem hiding this comment.
In the REST transport, the response payload logging attempts to serialize the requests.Response object (response) instead of the parsed protobuf message instance (resp). This will always raise an exception and result in response_payload being None. It should serialize resp instead. Additionally, catching all exceptions with a bare except: should be avoided; use except Exception: instead.
try:
response_payload = universalledger.QueryAccountResponse.to_json(
resp
)
except Exception:
response_payload = NoneReferences
- PEP 8 recommends avoiding bare except clauses because they catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. (link)
- For telemetry and observability logging, use broad exception handling (e.g.,
except Exception: pass) to ensure a fail-open contract where telemetry failures do not disrupt the main application flow or pollute user logs with warnings.
| try: | ||
| response_payload = universalledger.QueryDataResponse.to_json( | ||
| response | ||
| ) | ||
| except: | ||
| response_payload = None |
There was a problem hiding this comment.
In the REST transport, the response payload logging attempts to serialize the requests.Response object (response) instead of the parsed protobuf message instance (resp). This will always raise an exception and result in response_payload being None. It should serialize resp instead. Additionally, catching all exceptions with a bare except: should be avoided; use except Exception: instead.
| try: | |
| response_payload = universalledger.QueryDataResponse.to_json( | |
| response | |
| ) | |
| except: | |
| response_payload = None | |
| try: | |
| response_payload = universalledger.QueryDataResponse.to_json( | |
| resp | |
| ) | |
| except Exception: | |
| response_payload = None |
References
- PEP 8 recommends avoiding bare except clauses because they catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. (link)
- For telemetry and observability logging, use broad exception handling (e.g.,
except Exception: pass) to ensure a fail-open contract where telemetry failures do not disrupt the main application flow or pollute user logs with warnings.
| try: | ||
| response_payload = ( | ||
| universalledger.QueryTransactionStateResponse.to_json(response) | ||
| ) | ||
| except: | ||
| response_payload = None |
There was a problem hiding this comment.
In the REST transport, the response payload logging attempts to serialize the requests.Response object (response) instead of the parsed protobuf message instance (resp). This will always raise an exception and result in response_payload being None. It should serialize resp instead. Additionally, catching all exceptions with a bare except: should be avoided; use except Exception: instead.
| try: | |
| response_payload = ( | |
| universalledger.QueryTransactionStateResponse.to_json(response) | |
| ) | |
| except: | |
| response_payload = None | |
| try: | |
| response_payload = ( | |
| universalledger.QueryTransactionStateResponse.to_json(resp) | |
| ) | |
| except Exception: | |
| response_payload = None |
References
- PEP 8 recommends avoiding bare except clauses because they catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. (link)
- For telemetry and observability logging, use broad exception handling (e.g.,
except Exception: pass) to ensure a fail-open contract where telemetry failures do not disrupt the main application flow or pollute user logs with warnings.
| try: | ||
| response_payload = ( | ||
| universalledger.SubmitOperationalTransactionResponse.to_json( | ||
| response | ||
| ) | ||
| ) | ||
| except: | ||
| response_payload = None |
There was a problem hiding this comment.
In the REST transport, the response payload logging attempts to serialize the requests.Response object (response) instead of the parsed protobuf message instance (resp). This will always raise an exception and result in response_payload being None. It should serialize resp instead. Additionally, catching all exceptions with a bare except: should be avoided; use except Exception: instead.
| try: | |
| response_payload = ( | |
| universalledger.SubmitOperationalTransactionResponse.to_json( | |
| response | |
| ) | |
| ) | |
| except: | |
| response_payload = None | |
| try: | |
| response_payload = ( | |
| universalledger.SubmitOperationalTransactionResponse.to_json( | |
| resp | |
| ) | |
| ) | |
| except Exception: | |
| response_payload = None |
References
- PEP 8 recommends avoiding bare except clauses because they catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. (link)
- For telemetry and observability logging, use broad exception handling (e.g.,
except Exception: pass) to ensure a fail-open contract where telemetry failures do not disrupt the main application flow or pollute user logs with warnings.
| ): # pragma: NO COVER | ||
| try: | ||
| response_payload = ( | ||
| universalledger.SubmitTransactionResponse.to_json(response) | ||
| ) | ||
| except: |
There was a problem hiding this comment.
In the REST transport, the response payload logging attempts to serialize the requests.Response object (response) instead of the parsed protobuf message instance (resp). This will always raise an exception and result in response_payload being None. It should serialize resp instead. Additionally, catching all exceptions with a bare except: should be avoided; use except Exception: instead.
try:
response_payload = (
universalledger.SubmitTransactionResponse.to_json(resp)
)
except Exception:
response_payload = NoneReferences
- PEP 8 recommends avoiding bare except clauses because they catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. (link)
- For telemetry and observability logging, use broad exception handling (e.g.,
except Exception: pass) to ensure a fail-open contract where telemetry failures do not disrupt the main application flow or pollute user logs with warnings.
cd792f6 to
6cb7f4a
Compare
6cb7f4a to
5cb9c6b
Compare
Onboard google/cloud/universalledger/v1 API (google-cloud-universalledger).
Internal tracking bug http://b/590858913
PiperOrigin-RevId: 1030812305
Debug Info
System Details
Commands Executed
go run github.com/googleapis/librarian/cmd/librarian@v0.54.0 installgo run github.com/googleapis/librarian/cmd/librarian@v0.54.0 add google/cloud/universalledger/v1go run github.com/googleapis/librarian/cmd/librarian@v0.54.0 generate -v google-cloud-universalledgergo run github.com/googleapis/librarian/cmd/librarian@v0.54.0 tidygit add -Agit commit -m "feat(google/cloud/universalledger/v1): add google-cloud-universalledger"