Skip to content

fix: fail locally when no identifier is given#214

Merged
mmilanta merged 5 commits intomainfrom
fix/fail-on-cli-when-no-identifier-is-given
Mar 13, 2026
Merged

fix: fail locally when no identifier is given#214
mmilanta merged 5 commits intomainfrom
fix/fail-on-cli-when-no-identifier-is-given

Conversation

@mmilanta
Copy link
Contributor

No description provided.

@mmilanta mmilanta requested a review from a team as a code owner March 11, 2026 13:47
@mmilanta mmilanta force-pushed the fix/fail-on-cli-when-no-identifier-is-given branch from 4bb25c1 to 0293ae5 Compare March 12, 2026 14:43

i += 1
if identifier is None:
raise ValueError(f"Control server {url} is missing a --control-identifier")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also print a full traceback.

With something like this: https://github.com/snyk/agent-scan/blob/main/src/agent_scan/verify_api.py#L212

and https://github.com/snyk/agent-scan/blob/main/src/agent_scan/run.py#L11-L12

We can avoid the full stack trace. Maybe some sort of a common ValidationError that can be reused for other CLI flag validations? This will look cleaner.

def parse_control_servers(argv):
def parse_control_servers(argv) -> list[ControlServer]:
"""
Parse control server arguments from sys.argv.
Copy link
Contributor

@hemang-snyk hemang-snyk Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to explain the expectation here in a comment.

We are looking for blocks of --control-server, --control-server-H, --control-identifier flags. We expect these flags to be together in the same block one after the other before the next such block begins.

Ignore if this block behavior is already part of --help otherwise maybe another place to clarify this expectation is in --help.

Copy link
Contributor

@hemang-snyk hemang-snyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments - rest looks good, thank you!

identifier: str | None = None

i = 2
while i < len(block):
Copy link
Contributor

@hemang-snyk hemang-snyk Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a possibility of an infinite loop here?

In the while loop, we only increment i if we successfully match --control-server-H or --control-identifier and the following argument does not start with --.

If our block contains an unrecognized flag like --verbose, or if a flag is missing its value like
--control-identifier --some-other-flag, both the if elif conditions will fail - and the loop will be stuck forever?

We were earlier doing i += 1 in an else.

It would be nice to have a test for such cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but there is else, i+=1

@mmilanta mmilanta merged commit 3cb0f12 into main Mar 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants