Skip to content

fix(loader): avoid panic when dialers are missing#7066

Open
chuhuan88 wants to merge 1 commit intoprojectdiscovery:devfrom
chuhuan88:fix/loader-dialers-graceful-6674
Open

fix(loader): avoid panic when dialers are missing#7066
chuhuan88 wants to merge 1 commit intoprojectdiscovery:devfrom
chuhuan88:fix/loader-dialers-graceful-6674

Conversation

@chuhuan88
Copy link

@chuhuan88 chuhuan88 commented Feb 27, 2026

Proposed Changes

This PR removes a panic path in template loading when dialers are not initialized for the current execution ID.

  • In pkg/catalog/loader/loader.go, when protocolstate.GetDialersWithId(typesOpts.ExecutionId) returns nil, it now attempts a safe initialization via protocolstate.Init(typesOpts).
  • If initialization fails, the loader logs a warning and returns safely instead of panicking.
  • If dialers are still unavailable after init, the loader logs a warning and returns safely.

This keeps behavior stable for normal scanning flows while preventing hard crashes in non-scanning/partial-init paths.

Proof

Before

  • Loader could panic with:
    • panic("dialers with executionId ... not found")

After

  • Loader no longer panics on missing dialers.
  • It attempts init, then degrades gracefully with warning logs if dialers are still unavailable.

Local verification

  • Previously validated in local environment:
    • go test ./pkg/catalog/loader -count=1

Checklist

  • PR targets the correct base branch (dev)
  • Changes are scoped to the reported issue
  • Added proof of behavior change (before/after + test command)
  • Full repository checks
  • Additional tests/docs (not required for this minimal fix)

/claim #6674

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for missing initialization states with automatic fallback initialization.
    • Replaced abrupt failures with graceful degradation and warning logs, enhancing application stability.

Attempt protocolstate initialization when dialers are absent and return safely with warnings if still unavailable.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

Walkthrough

In LoadTemplatesWithTags, missing dialers now trigger a fallback initialization via protocolstate.Init() instead of panicking. If initialization fails or dialers remain nil, a warning is logged and the function returns early without crashing.

Changes

Cohort / File(s) Summary
Error Handling Improvement
pkg/catalog/loader/loader.go
Replaced panic on missing dialers with fallback protocolstate.Init() call and graceful early return with warning log.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 No more panic when dialers stray,
A fallback init saves the day,
Log a warning, exit with grace,
Robustness wins the rabbit race! 🏃‍♂️✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(loader): avoid panic when dialers are missing' directly and concisely describes the main change: removing a panic condition when dialers are not found.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/catalog/loader/loader.go (1)

718-729: LGTM - Graceful degradation replaces panic appropriately.

The fallback initialization pattern correctly prevents hard crashes in partial-init paths. The flow is safe since this check executes before concurrent goroutines spawn.

Minor observation: The dialers variable is assigned but not directly used after this block (dialers are accessed through global state downstream). Consider simplifying for clarity:

♻️ Optional simplification
-	dialers := protocolstate.GetDialersWithId(typesOpts.ExecutionId)
-	if dialers == nil {
+	if protocolstate.GetDialersWithId(typesOpts.ExecutionId) == nil {
 		if err := protocolstate.Init(typesOpts); err != nil {
 			store.logger.Warning().Msgf("could not initialize dialers for executionId %s: %s", typesOpts.ExecutionId, err)
 			return loadedTemplates.Slice
 		}
-		dialers = protocolstate.GetDialersWithId(typesOpts.ExecutionId)
-		if dialers == nil {
+		if protocolstate.GetDialersWithId(typesOpts.ExecutionId) == nil {
 			store.logger.Warning().Msgf("dialers with executionId %s not found", typesOpts.ExecutionId)
 			return loadedTemplates.Slice
 		}
 	}

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/catalog/loader/loader.go` around lines 718 - 729, The local variable
dialers is assigned but never used downstream; simplify the block by removing
the unused dialers variable and directly checking
protocolstate.GetDialersWithId(typesOpts.ExecutionId) for nil, calling
protocolstate.Init(typesOpts) on miss, re-checking GetDialersWithId, and keeping
the existing store.logger.Warning messages and return loadedTemplates.Slice
paths (referencing protocolstate.GetDialersWithId, protocolstate.Init,
typesOpts.ExecutionId, store.logger.Warning, and loadedTemplates.Slice).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/catalog/loader/loader.go`:
- Around line 718-729: The local variable dialers is assigned but never used
downstream; simplify the block by removing the unused dialers variable and
directly checking protocolstate.GetDialersWithId(typesOpts.ExecutionId) for nil,
calling protocolstate.Init(typesOpts) on miss, re-checking GetDialersWithId, and
keeping the existing store.logger.Warning messages and return
loadedTemplates.Slice paths (referencing protocolstate.GetDialersWithId,
protocolstate.Init, typesOpts.ExecutionId, store.logger.Warning, and
loadedTemplates.Slice).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9142eae and 8e66ea9.

📒 Files selected for processing (1)
  • pkg/catalog/loader/loader.go

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant