Skip to content

Replace panic with error handling in template loader when dialers are missing #6674

@coderabbitai

Description

@coderabbitai

Description

The template loader in pkg/catalog/loader/loader.go (around lines 684-703) currently panics when protocolstate.GetDialersWithId() returns nil. This is too harsh for a public API that may be exercised in non-scanning flows.

Current Behavior

When dialers are not initialized, the code panics:

dialers := protocolstate.GetDialersWithId(typesOpts.ExecutionId)
if dialers == nil {
    panic("dialers with executionId " + typesOpts.ExecutionId + " not found")
}

Expected Behavior

The loader should return a proper error instead of panicking, allowing callers to handle the situation gracefully. The broader codebase pattern returns fmt.Errorf when dialers are missing rather than panicking.

Suggested Changes

  1. Replace the panic with proper error return (e.g., return fmt.Errorf("dialers with executionId %s not found", typesOpts.ExecutionId))
  2. Update the loader function signature to propagate the error
  3. Update callers to handle the error appropriately
  4. Add documentation noting the new error condition

Context

Callers like lazy auth template loading (internal/runner/lazy.go) and automatic tech detection (pkg/protocols/common/automaticscan/) invoke LoadTemplates/LoadTemplatesWithTags without guaranteed dialer initialization.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    $100Type: BugInconsistencies or issues which will cause an issue or problem for users or implementors.💎 Bounty💰 Rewarded

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions