Replace panic with error handling in template loader#7069
Replace panic with error handling in template loader#7069teredasites wants to merge 1 commit intoprojectdiscovery:devfrom
Conversation
… missing - Replace both panic() calls in LoadTemplatesWithTags with fmt.Errorf returns - Update LoadTemplatesWithTags signature to return ([]*templates.Template, error) - Update LoadTemplates signature to match - Update Store.Load() to return error - Move dialers nil check before waitgroup creation to avoid unnecessary allocation - Inline the dialers variable (only used for nil check) - Update all callers to handle and propagate errors: - internal/runner/runner.go - internal/runner/lazy.go - internal/server/nuclei_sdk.go - lib/sdk.go - lib/multi.go - cmd/integration-test/library.go - pkg/protocols/common/automaticscan/util.go - Update benchmark tests to handle two-value return Fixes projectdiscovery#6674
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (9)
WalkthroughThis change adds comprehensive error handling to template loading operations across the codebase. The core loader package public API methods— Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 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 |
Neo - PR Security ReviewNo security issues found Highlights
Comment |
Proposed Changes
Replace both
panic()calls in the template loader'sLoadTemplatesWithTagsfunction with proper error returns, allowing callers to handle missing dialers and wait group failures gracefully instead of crashing.Changes:
LoadTemplatesWithTagsandLoadTemplatesnow return([]*templates.Template, error)instead of just[]*templates.TemplateStore.Load()now returnserrorinstead of nothingpanic("dialers with executionId ... not found")andpanic("could not create wait group")replaced withfmt.Errorf()error returnsdialersvariable (was only used for the nil check)internal/runner/runner.gointernal/runner/lazy.gointernal/server/nuclei_sdk.golib/sdk.golib/multi.gocmd/integration-test/library.gopkg/protocols/common/automaticscan/util.goProof
Before
When dialers are not initialized, the application panics with an unrecoverable crash:
After
Errors are returned and propagated up the call chain:
Callers receive the error and can handle it (log, retry, return) instead of crashing.
Compilation verified
All function signatures maintain backward-compatible behavior: callers already checked for nil/empty template slices, and now additionally check the error return.
Checklist
dev)Fixes #6674
/claim #6674
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests