Skip to content

fix: replace fatalError with thrown error in signWithOperator#595

Open
rwalworth wants to merge 1 commit intomainfrom
fix/transaction-sign-with-operator-fatal-error
Open

fix: replace fatalError with thrown error in signWithOperator#595
rwalworth wants to merge 1 commit intomainfrom
fix/transaction-sign-with-operator-fatal-error

Conversation

@rwalworth
Copy link
Copy Markdown
Contributor

Summary

This PR fixes a crash in signWithOperator(_:) that occurred when the client had no operator configured. Instead of calling fatalError, which unconditionally terminates the process, the method now throws HError.noPayerAccountOrTransactionId, giving callers the opportunity to handle the error gracefully.

Key Changes:

  • Replace fatalError("todo: error here (Client had no operator)") with throw HError.noPayerAccountOrTransactionId in Transaction.signWithOperator(_:)

Changes

Replace fatalError with a Thrown Error

Problem: Transaction.signWithOperator(_:) called fatalError when the client had no operator, crashing the entire process instead of surfacing a recoverable error.

Discovery: This bug was surfaced by the Swift SDK TCK compatibility workflow (hiero-sdk-tck#636). The HieroTCK server runs inside a Vapor process — when a test triggered signWithOperator on a client with no operator set, the fatalError killed the entire server process mid-run, causing all 317 subsequent TCK tests to fail with ECONNREFUSED on port 8544.

Root Cause: A // TODO stub was left in place that used fatalError as a placeholder.

Fix: The method already throws (its signature is throws), and HError.noPayerAccountOrTransactionId is the established error for this exact condition — already used in three other locations in the codebase (Transaction.swift:786, Transaction.swift:901, ChunkedTransaction.swift:217). Replacing the fatalError with this throw makes the behavior consistent and recoverable.

Files Changed:


Testing

Test Plan:

  • Verify the project builds successfully
  • Verify that calling signWithOperator on a client without an operator now throws instead of crashing
  • Confirm existing tests continue to pass

Files Changed Summary

Category Files
Source Sources/Hiero/Transaction.swift

Breaking Changes

None. The method signature was already declared throws. Callers that previously crashed (due to fatalError) will now receive a thrown HError.noPayerAccountOrTransactionId error, which is strictly an improvement.

Signed-off-by: Rob Walworth <robert.walworth@swirldslabs.com>
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant