fix(app): return InitChainer errors instead of panics#317
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughThe PR changes Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/app_test.go (1)
54-67: Assert nil response on error to fully lock theInitChainercontract.Line 63 currently captures only
err. Since this PR’s contract is “nilresponse + error on failure,” assertrespis nil too.Suggested test hardening
func TestKiichainApp_InitChainerReturnsErrorForInvalidGenesisJSON(t *testing.T) { app := kiihelpers.Setup(t) req := &abci.RequestInitChain{ AppStateBytes: []byte("{ invalid json }"), } - var err error + var ( + resp *abci.ResponseInitChain + err error + ) require.NotPanics(t, func() { - _, err = app.InitChainer(app.NewContext(false), req) + resp, err = app.InitChainer(app.NewContext(false), req) }) + require.Nil(t, resp) require.Error(t, err) require.ErrorContains(t, err, "failed to unmarshal genesis state") }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/app_test.go` around lines 54 - 67, The test TestKiichainApp_InitChainerReturnsErrorForInvalidGenesisJSON should also assert that the response from app.InitChainer is nil when an error occurs; change the call to capture the response (resp, err = app.InitChainer(...)) and add require.Nil(t, resp) after the NotPanics block (before or alongside require.Error(t, err)) to enforce the "nil response + error" contract for InitChainer on invalid genesis JSON; reference app.InitChainer and the TestKiichainApp_InitChainerReturnsErrorForInvalidGenesisJSON test to locate and update the assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/app_test.go`:
- Around line 54-67: The test
TestKiichainApp_InitChainerReturnsErrorForInvalidGenesisJSON should also assert
that the response from app.InitChainer is nil when an error occurs; change the
call to capture the response (resp, err = app.InitChainer(...)) and add
require.Nil(t, resp) after the NotPanics block (before or alongside
require.Error(t, err)) to enforce the "nil response + error" contract for
InitChainer on invalid genesis JSON; reference app.InitChainer and the
TestKiichainApp_InitChainerReturnsErrorForInvalidGenesisJSON test to locate and
update the assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8e774430-d5ff-4aa7-a06f-7d3cb64551af
📒 Files selected for processing (2)
app/app.goapp/app_test.go
|
@coderabbitai addressed, thanks. Implemented the suggested hardening in TestKiichainApp_InitChainerReturnsErrorForInvalidGenesisJSON by capturing resp, err = app.InitChainer(...) and asserting require.Nil(t, resp) alongside the error assertions. Validation run:
|
|
Tip For best results, initiate chat on the files or code changes.
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
|
This PR is a copy from #309 |
Summary
Testing
Closes #264