Skip to content

Some SDK error paths print directly to stdout/stderr during exception and fallback handling #2403

Description

@sudo-anshul

Description

While looking through a few query and network paths, I noticed that some SDK
runtime code calls print(...) directly and, in a few places,
traceback.print_exc() as part of internal error handling.

From a contributor/user point of view, this feels a little surprising because
the SDK is a library, and these paths can produce console output even when:

  • the caller is already handling the exception
  • the method re-raises the same exception immediately
  • the SDK falls back and continues successfully

I think it would be nicer if these paths either raised/returned quietly or used
the SDK's logging system instead of printing directly.

Steps to reproduce

Repro 1: query builder prints before re-raising

from hiero_sdk_python.query.token_info_query import TokenInfoQuery

TokenInfoQuery()._make_request()

Actual behavior:

  • raises ValueError("Token ID must be set before making the request.")
  • also prints Exception in _make_request: Token ID must be set before making the request.

Expected behavior:

  • raise the exception without printing directly to stdout

Repro 2: query builder prints and emits traceback

from hiero_sdk_python.query.account_balance_query import CryptoGetAccountBalanceQuery
from hiero_sdk_python.account.account_id import AccountId
from hiero_sdk_python.contract.contract_id import ContractId

query = CryptoGetAccountBalanceQuery()
query.account_id = AccountId(0, 0, 123)
query.contract_id = ContractId(0, 0, 456)
query._make_request()

Actual behavior:

  • raises ValueError("Specify either account_id or contract_id, not both.")
  • prints an error message to stdout
  • emits a traceback to stderr

Expected behavior:

  • raise the exception without direct console output

Repro 3: network fallback still prints

If mirror-node discovery fails for a hosted network, Network("testnet") can
still initialize successfully by falling back to default nodes, but it prints
the mirror-node fetch failure to stdout during that process.

Actual behavior:

  • network initialization succeeds
  • console output still includes Error fetching nodes from mirror node API: ...

Expected behavior:

  • fallback should remain intact
  • logging/output should be opt-in, not printed directly by the SDK

Additional context

Verified affected locations include:

  • src/hiero_sdk_python/query/token_info_query.py
  • src/hiero_sdk_python/query/account_info_query.py
  • src/hiero_sdk_python/query/account_balance_query.py
  • src/hiero_sdk_python/query/token_nft_info_query.py
  • src/hiero_sdk_python/file/file_info_query.py
  • src/hiero_sdk_python/client/network.py

Examples:

  • src/hiero_sdk_python/query/account_balance_query.py:112-115
  • src/hiero_sdk_python/client/network.py:191-212

This seems separate from documentation/example print(...) usage. I am only
referring to runtime library paths that emit output during normal exception or
fallback handling.

Also, the repo already has logging infrastructure and other SDK paths appear to
use logger-based diagnostics, so these spots feel a bit inconsistent with that
direction.

Why this matters

This can be noisy for:

  • applications embedding the SDK
  • CLI tools that want explicit control over output
  • tests that assert clean stdout/stderr
  • services/workers using structured logging

Possible fix direction

Maybe one of these approaches would fit:

  • remove direct print(...) / traceback.print_exc() from these library paths
  • re-raise/return without printing directly
  • or route diagnostics through the SDK's existing logging mechanisms

I am not suggesting any behavior change to the exception/fallback logic itself,
just to the direct console side effects.

Environment

  • Hedera network: testnet for the network fallback reproduction

Metadata

Metadata

Assignees

Labels

approvedIssue has been approved by team memberskill: intermediaterequires some knowledge of the codebase with some defined steps to implement or examples

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions