Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Refactor Error Aggregation for Missing Parameters #37

@sourcery-ai

Description

@sourcery-ai

The current implementation of error aggregation for missing parameters in the codebase involves concatenating missing field names, which can lead to extra spaces or punctuation. This approach can be improved for better maintainability and clarity by using an array to collect missing keys and then joining them into a string.

Suggested Improvement:

Instead of concatenating strings directly, use an array to gather all missing parameters and then join them with a separator. This method not only enhances readability but also reduces the risk of formatting errors.

Proposed Code:

let missingParams: string[] = [];
if (!body.compose_spec) {
    missingParams.push("compose_spec");
}
if (!body.automatic_reboot_on_error) {
    missingParams.push("automatic_reboot_on_error");
}
if (!body.source) {
    missingParams.push("source");
}
if (!body.name) {
    missingParams.push("name");
}

if (missingParams.length > 0) {
    const errMsg = `Missing values of: ${missingParams.join("; ")}`;
    return responseHandler.error(set, errMsg, errMsg);
}

Action Items:

  • Refactor the existing code to implement the suggested improvement.
  • Ensure that any further usage of the error message variable is updated accordingly if it depended on the previous concatenation approach.

This change will improve the maintainability and clarity of the error handling code.


I created this issue for @Its4Nik from #33 (comment).

Tips and commands

Interacting with Sourcery

  • Generate a plan of action: Comment @sourcery-ai plan on this issue.
  • Generate a pull request for this issue: Comment @sourcery-ai develop to
    generate a PR that addresses this issue.

Getting Help

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions