Skip to content

CLI Code Quality and Logic Issues #342

@Ansita20

Description

@Ansita20

Describe the bug

CLI Code Quality and Logic Issues

Summary

While reviewing the CLI codebase, several issues were identified that affect compilation, code readability, and runtime behavior. These issues include function name typos and a logic bug related to file path normalization.


Issue 1: Typo in Command Constructor Function

Severity

🔴 Critical – Causes compilation error

Description

The function responsible for creating the CLI command is misspelled as NewCommad().

Because of this typo, the function cannot be resolved correctly, leading to a compilation error when referenced elsewhere in the code.

Location

Definition: cmd/cmd.go (Line 25)
Usage: main.go (Line 11)

Current Code

// cmd/cmd.go
func NewCommad() *cobra.Command {
    // ...
}

// main.go
command := cmd.NewCommad()

Expected Code

// cmd/cmd.go
func NewCommand() *cobra.Command {
// ...
}

// main.go
command := cmd.NewCommand()

Error Message

undefined: cmd.NewCommad

Suggested Fix

Rename the function and update all references from:

NewCommad()

to

NewCommand()

Issue 2: Typo in WatchManager Constructor

Severity

🔴 Critical – Naming inconsistency

Description

The constructor for WatchManager is misspelled as NewWatchManger().

Although the code compiles because the same typo is used everywhere, it creates confusion and does not match the struct name.

Locations

Definition: pkg/watcher/watchManager.go
Usage: cmd/import.go
Usage: watcher/main.go

Current Code

func NewWatchManger(configPath string) (*WatchManager, error) {
// ...
}

Expected Code

func NewWatchManager(configPath string) (*WatchManager, error) {
// ...
}

Impact

  • Poor code readability

  • Naming inconsistency

  • Confusion for contributors

Suggested Fix

Rename the function and update all call sites from:

NewWatchManger()

to

NewWatchManager()

Issue 3: File Path Normalization Happens Too Late

Severity

🟡 High – Logic bug

Description

The import command normalizes the file path (removing ./) after calling UploadArtifact().

This creates inconsistencies between:

  • the uploaded artifact path

  • the watcher configuration path

As a result, the file watcher may fail to detect file changes.

Location

cmd/import.go

Current Code

msg, err := mc.UploadArtifact(f, mainArtifact)

if watch {
if strings.HasPrefix(f, "./") {
f = strings.TrimPrefix(f, "./")
}

watchCfg.UpsertEntry(config.WatchEntry{
    FilePath: f,
})

}

Problem

Example scenario:

Uploaded artifact path

./api.json

Watcher path

api.json

This mismatch can cause watcher failures.

Expected Behavior

File path normalization should happen before the upload operation so both components use the same path.

Expected Code

if strings.HasPrefix(f, "./") {
f = strings.TrimPrefix(f, "./")
}

msg, err := mc.UploadArtifact(f, mainArtifact)

if watch {
watchCfg.UpsertEntry(config.WatchEntry{
FilePath: f,
})
}

Impact

  • File watcher may miss change events

  • Watch mode may silently fail

  • Inconsistent path handling


Proposed Fix Summary

Issue Type Severity
NewCommad() typo Naming bug 🔴 Critical
NewWatchManger() typo Naming bug 🔴 Critical
File path normalization order Logic bug 🟡 High

Conclusion

Fixing these issues will:

  • Resolve compilation failures

  • Improve code readability and consistency

  • Ensure reliable file watcher behavior in watch mode

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Microcks version or git rev

No response

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions