fix(dapp-factory): remove illegal await in constructor and fix exit code#246
Open
fix(dapp-factory): remove illegal await in constructor and fix exit code#246
Conversation
- Replace dynamic `await import('crypto')` in Web3Pipeline constructor
with a static top-level import; constructors cannot be async so the
dynamic import was a guaranteed runtime crash.
- Fix `main().catch(console.error)` in web3factory.ts to call
`process.exit(1)` on rejection so CI and callers receive a non-zero
exit code on failure.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two bugs in
dapp-factory/that cause runtime failures:1.
awaitinside a synchronous constructor (guaranteed crash)dapp-factory/pipeline/web3_pipeline.tsusedawait import('crypto')insideWeb3Pipeline's constructor, which is notasync. This is illegal in TypeScript/JavaScript — constructors cannotawait. The expression resolves to aPromiseat runtime, meaning.createHash()would be called on a Promise object instead of thecryptomodule, crashing everynew Web3Pipeline(...)call.Fix: Add a static top-level
import * as crypto from 'crypto'(Node.js built-in, no dynamic load needed) and remove the dynamic import line.2.
main().catch(console.error)swallows the exit codedapp-factory/web3factory.tsended withmain().catch(console.error), which logs the error but exits with code0. Any caller (CI, shell scripts) would see success even on failure.Fix: Changed to
main().catch(err => { console.error(err); process.exit(1); }).Why
new Web3Pipeline()to throw a TypeError on every invocation — the dApp pipeline can't start at all.Tested
dapp-factory/TypeScript compiles without errors after the import change.🤖 Generated with Claude Code