Skip to content

Commit 597ecb3

Browse files
authored
cmd/evm: return json error if unmarshalling from stdin fails (ethereum#22871)
* cmd/evm: return json error if unmarshalling from stdin fails * cmd/evm: make error capitalizations uniform (all lowercase starts) * cmd/evm: capitalize error sent directly to stderror
1 parent addd882 commit 597ecb3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

cmd/evm/internal/t8ntool/transition.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ func Main(ctx *cli.Context) error {
142142
// Figure out the prestate alloc
143143
if allocStr == stdinSelector || envStr == stdinSelector || txStr == stdinSelector {
144144
decoder := json.NewDecoder(os.Stdin)
145-
decoder.Decode(inputData)
145+
if err := decoder.Decode(inputData); err != nil {
146+
return NewError(ErrorJson, fmt.Errorf("failed unmarshaling stdin: %v", err))
147+
}
146148
}
147149
if allocStr != stdinSelector {
148150
inFile, err := os.Open(allocStr)
@@ -152,7 +154,7 @@ func Main(ctx *cli.Context) error {
152154
defer inFile.Close()
153155
decoder := json.NewDecoder(inFile)
154156
if err := decoder.Decode(&inputData.Alloc); err != nil {
155-
return NewError(ErrorJson, fmt.Errorf("Failed unmarshaling alloc-file: %v", err))
157+
return NewError(ErrorJson, fmt.Errorf("failed unmarshaling alloc-file: %v", err))
156158
}
157159
}
158160
prestate.Pre = inputData.Alloc
@@ -167,7 +169,7 @@ func Main(ctx *cli.Context) error {
167169
decoder := json.NewDecoder(inFile)
168170
var env stEnv
169171
if err := decoder.Decode(&env); err != nil {
170-
return NewError(ErrorJson, fmt.Errorf("Failed unmarshaling env-file: %v", err))
172+
return NewError(ErrorJson, fmt.Errorf("failed unmarshaling env-file: %v", err))
171173
}
172174
inputData.Env = &env
173175
}
@@ -180,7 +182,7 @@ func Main(ctx *cli.Context) error {
180182
// Construct the chainconfig
181183
var chainConfig *params.ChainConfig
182184
if cConf, extraEips, err := tests.GetChainConfig(ctx.String(ForknameFlag.Name)); err != nil {
183-
return NewError(ErrorVMConfig, fmt.Errorf("Failed constructing chain configuration: %v", err))
185+
return NewError(ErrorVMConfig, fmt.Errorf("failed constructing chain configuration: %v", err))
184186
} else {
185187
chainConfig = cConf
186188
vmConfig.ExtraEips = extraEips
@@ -197,7 +199,7 @@ func Main(ctx *cli.Context) error {
197199
defer inFile.Close()
198200
decoder := json.NewDecoder(inFile)
199201
if err := decoder.Decode(&txsWithKeys); err != nil {
200-
return NewError(ErrorJson, fmt.Errorf("Failed unmarshaling txs-file: %v", err))
202+
return NewError(ErrorJson, fmt.Errorf("failed unmarshaling txs-file: %v", err))
201203
}
202204
} else {
203205
txsWithKeys = inputData.Txs
@@ -206,7 +208,7 @@ func Main(ctx *cli.Context) error {
206208
signer := types.MakeSigner(chainConfig, big.NewInt(int64(prestate.Env.Number)))
207209

208210
if txs, err = signUnsignedTransactions(txsWithKeys, signer); err != nil {
209-
return NewError(ErrorJson, fmt.Errorf("Failed signing transactions: %v", err))
211+
return NewError(ErrorJson, fmt.Errorf("failed signing transactions: %v", err))
210212
}
211213

212214
// Iterate over all the tests, run them and aggregate the results
@@ -277,7 +279,7 @@ func signUnsignedTransactions(txs []*txWithKey, signer types.Signer) (types.Tran
277279
// This transaction needs to be signed
278280
signed, err := types.SignTx(tx, signer, key)
279281
if err != nil {
280-
return nil, NewError(ErrorJson, fmt.Errorf("Tx %d: failed to sign tx: %v", i, err))
282+
return nil, NewError(ErrorJson, fmt.Errorf("tx %d: failed to sign tx: %v", i, err))
281283
}
282284
signedTxs = append(signedTxs, signed)
283285
} else {

0 commit comments

Comments
 (0)