Skip to content

Fix unreachable duplicate validation logic in insertErms #67427

@Nithin0620

Description

@Nithin0620

Fix unreachable duplicate validation logic in insertErms

Description

The insertErms function currently combines two different validation checks into a single condition:

if (!erms || erms.length <= 1)

This creates a logic issue where the later validation check for insufficient erms length becomes unreachable dead code.

Problem

The first condition already throws an error when:

  • erms is not provided
  • erms.length <= 1

Because of this, any subsequent validation specifically checking the length of erms will never execute.

This makes the second validation block redundant and prevents proper separation of error handling logic.

Expected Behavior

The function should independently validate:

  1. Whether erms exists
  2. Whether erms contains at least 2 elements

Each validation should have its own dedicated condition and error handling.

Proposed Solution

Split the combined validation into two separate checks:

if (!erms) {
  // handle missing erms
}

if (erms.length <= 1) {
  // handle insufficient length
}

Benefits

  • Removes unreachable dead code
  • Improves code readability
  • Makes validation logic easier to understand and maintain
  • Ensures each error condition is handled independently
  • Preserves intended validation behavior

Additional Context

This issue was identified while reviewing the validation flow in insertErms, where the second error check could never be reached due to the earlier combined condition already handling the same case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions