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:
- Whether
erms exists
- 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.
Fix unreachable duplicate validation logic in
insertErmsDescription
The
insertErmsfunction currently combines two different validation checks into a single condition:This creates a logic issue where the later validation check for insufficient
ermslength becomes unreachable dead code.Problem
The first condition already throws an error when:
ermsis not providederms.length <= 1Because of this, any subsequent validation specifically checking the length of
ermswill never execute.This makes the second validation block redundant and prevents proper separation of error handling logic.
Expected Behavior
The function should independently validate:
ermsexistsermscontains at least 2 elementsEach validation should have its own dedicated condition and error handling.
Proposed Solution
Split the combined validation into two separate checks:
Benefits
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.