Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/account/account_records_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import traceback
import logging

from hiero_sdk_python.account.account_id import AccountId
from hiero_sdk_python.channels import _Channel
Expand All @@ -16,6 +16,9 @@
from hiero_sdk_python.transaction.transaction_record import TransactionRecord


logger = logging.getLogger(__name__)


class AccountRecordsQuery(Query):
"""
A query to retrieve records about a specific Account.
Expand Down Expand Up @@ -76,8 +79,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
11 changes: 9 additions & 2 deletions src/hiero_sdk_python/client/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import logging
import secrets
import time
from typing import Any
Expand All @@ -15,6 +16,9 @@
from hiero_sdk_python.node import _Node


logger = logging.getLogger(__name__)


class Network:
"""Manages the network configuration for connecting to the Hedera network."""

Expand Down Expand Up @@ -188,7 +192,7 @@ def _fetch_nodes_from_mirror_node(self) -> list[_Node]:
"""
base_url: str | None = self.MIRROR_NODE_URLS.get(self.network)
if not base_url:
print(f"No known mirror node URL for network='{self.network}'. Skipping fetch.")
logger.warning("No known mirror node URL for network='%s'. Skipping fetch.", self.network)
return []

url: str = f"{base_url}/api/v1/network/nodes?limit=100&order=desc"
Expand All @@ -209,7 +213,10 @@ def _fetch_nodes_from_mirror_node(self) -> list[_Node]:

return nodes
except requests.RequestException as e:
Comment thread
exploreriii marked this conversation as resolved.
print(f"Error fetching nodes from mirror node API: {e}")
logger.error("Error fetching nodes from mirror node API: %s", e)
return []
Comment on lines 215 to +217

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

MINOR — Preserve traceback context for mirror-node request failures.

This branch logs only str(e), so the structured record has no exc_info, unlike the parsing branch and query handlers. Add exc_info=True (or use logger.exception) and assert traceback retention in the request-failure test.

except (ValueError, KeyError, TypeError, IndexError, AttributeError) as e:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just fall back to a generic Exception here instead of listing all the possible exception types

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem comes from NodeAddress._from_dict, where missing keys pass None thus you get the variety of type erorrs/attribute errors/etc
So i think we should look at is improve none handling, which maybe should be a different PR what do you think @manishdait ?

logger.error("Error parsing mirror node API response: %s", e, exc_info=True)
return []

def _fetch_nodes_from_default_nodes(self) -> list[_Node]:
Expand Down
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/contract/contract_bytecode_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import traceback
import logging

from hiero_sdk_python.channels import _Channel
from hiero_sdk_python.client.client import Client
Expand All @@ -19,6 +19,9 @@
from hiero_sdk_python.query.query import Query


logger = logging.getLogger(__name__)


class ContractBytecodeQuery(Query):
"""
A query to retrieve the bytecode of a specific Contract.
Expand Down Expand Up @@ -80,8 +83,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/contract/contract_call_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import annotations

import traceback
import logging

from hiero_sdk_python.account.account_id import AccountId
from hiero_sdk_python.channels import _Channel
Expand All @@ -23,6 +23,9 @@
from hiero_sdk_python.query.query import Query


logger = logging.getLogger(__name__)


class ContractCallQuery(Query):
"""
A query to call a contract on the network.
Expand Down Expand Up @@ -160,8 +163,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/contract/contract_info_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import traceback
import logging

from hiero_sdk_python.channels import _Channel
from hiero_sdk_python.client.client import Client
Expand All @@ -18,6 +18,9 @@
from hiero_sdk_python.query.query import Query


logger = logging.getLogger(__name__)


class ContractInfoQuery(Query):
"""
A query to retrieve information about a specific Contract.
Expand Down Expand Up @@ -76,8 +79,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
7 changes: 6 additions & 1 deletion src/hiero_sdk_python/file/file_contents_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import logging

from hiero_sdk_python.channels import _Channel
from hiero_sdk_python.client.client import Client
from hiero_sdk_python.executable import _Method
Expand All @@ -15,6 +17,9 @@
from hiero_sdk_python.query.query import Query


logger = logging.getLogger(__name__)


class FileContentsQuery(Query):
"""
A query to retrieve the contents of a specific File.
Expand Down Expand Up @@ -76,7 +81,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/file/file_info_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

import traceback
import logging

from hiero_sdk_python.channels import _Channel
from hiero_sdk_python.client.client import Client
Expand All @@ -14,6 +14,9 @@
from hiero_sdk_python.query.query import Query


logger = logging.getLogger(__name__)


class FileInfoQuery(Query):
"""
A query to retrieve information about a specific File.
Expand Down Expand Up @@ -75,8 +78,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/query/account_balance_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import traceback
import logging
from typing import Any

from hiero_sdk_python.account.account_balance import AccountBalance
Expand All @@ -13,6 +13,9 @@
from hiero_sdk_python.query.query import Query


logger = logging.getLogger(__name__)


class CryptoGetAccountBalanceQuery(Query):
"""
A query to retrieve the balance of a specific account from the Hedera network.
Expand Down Expand Up @@ -110,8 +113,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
7 changes: 6 additions & 1 deletion src/hiero_sdk_python/query/account_info_query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import logging

from hiero_sdk_python.account.account_id import AccountId
from hiero_sdk_python.account.account_info import AccountInfo
from hiero_sdk_python.channels import _Channel
Expand All @@ -8,6 +10,9 @@
from hiero_sdk_python.query.query import Query


logger = logging.getLogger(__name__)


class AccountInfoQuery(Query):
"""
A query to retrieve information about a specific Account.
Expand Down Expand Up @@ -67,7 +72,7 @@ def _make_request(self):

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
7 changes: 6 additions & 1 deletion src/hiero_sdk_python/query/token_info_query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import logging

from hiero_sdk_python.channels import _Channel
from hiero_sdk_python.client.client import Client
from hiero_sdk_python.executable import _Method
Expand All @@ -9,6 +11,9 @@
from hiero_sdk_python.tokens.token_info import TokenInfo


logger = logging.getLogger(__name__)


class TokenInfoQuery(Query):
"""
A query to retrieve information about a specific Token.
Expand Down Expand Up @@ -69,7 +74,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/query/token_nft_info_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import traceback
import logging

from hiero_sdk_python.channels import _Channel
from hiero_sdk_python.client.client import Client
Expand All @@ -11,6 +11,9 @@
from hiero_sdk_python.tokens.token_nft_info import TokenNftInfo


logger = logging.getLogger(__name__)


class TokenNftInfoQuery(Query):
"""
A query to retrieve information about a specific Hedera NFT.
Expand Down Expand Up @@ -69,8 +72,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/query/topic_info_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import traceback
import logging
from typing import Any

from hiero_sdk_python.channels import _Channel
Expand All @@ -13,6 +13,9 @@
from hiero_sdk_python.response_code import ResponseCode


logger = logging.getLogger(__name__)


class TopicInfoQuery(Query):
"""
A query to retrieve information about a specific Hedera topic.
Expand Down Expand Up @@ -99,8 +102,7 @@ def _make_request(self) -> query_pb2.Query:
return query

except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
8 changes: 5 additions & 3 deletions src/hiero_sdk_python/query/transaction_get_receipt_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import traceback
import logging

from hiero_sdk_python.channels import _Channel
from hiero_sdk_python.client.client import Client
Expand All @@ -19,6 +19,9 @@
from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt


logger = logging.getLogger(__name__)


class TransactionGetReceiptQuery(Query):
"""
A query to retrieve the receipt of a specific transaction from the Hedera network.
Expand Down Expand Up @@ -184,8 +187,7 @@ def _make_request(self) -> query_pb2.Query:

return query
except Exception as e:
print(f"Exception in _make_request: {e}")
traceback.print_exc()
logger.error("Exception in _make_request: %s", e, exc_info=True)
raise

def _get_method(self, channel: _Channel) -> _Method:
Expand Down
Loading