Skip to content

feat: implement M2 contracts (issues 5, 6, 7, 8) - #26

Merged
mendsec merged 1 commit into
developfrom
feature/m2-contracts
Jun 5, 2026
Merged

mendsec merged 1 commit into
developfrom
feature/m2-contracts

Conversation

@mendsec

@mendsec mendsec commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

This PR closes issues #5, #6, #7, and #8 by introducing a structured error taxonomy, schema versioning, establishing JSON as the canonical export format, and standardizing scan lifecycle events.

Closes #5, Closes #6, Closes #7, Closes #8

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a structured sentinel error taxonomy under pkg/coreerr and integrates it across target parsing, exporters, and the scanning engine. It also enhances the scanning engine to support rich lifecycle events (start, complete, cancel, warning) and updates the documentation and quickstart examples accordingly. The review feedback recommends wrapping errors returned by parseCIDR with coreerr.ErrInvalidInput to maintain error consistency, and updating the event documentation to explicitly warn consumers that callbacks are invoked concurrently and must be thread-safe.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/targets/parse.go
Comment on lines 18 to 19
if strings.Contains(input, "/") {
return parseCIDR(input)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The error returned by parseCIDR is returned directly without being wrapped by coreerr.ErrInvalidInput. This breaks the structured error taxonomy for CIDR parsing errors, making it impossible for callers to detect them using errors.Is(err, coreerr.ErrInvalidInput).

Please wrap the error returned by parseCIDR to ensure consistent error handling.

Suggested change
if strings.Contains(input, "/") {
return parseCIDR(input)
if strings.Contains(input, "/") {
ips, err := parseCIDR(input)
if err != nil {
return nil, fmt.Errorf("%w: %v", coreerr.ErrInvalidInput, err)
}
return ips, nil
}

Comment thread docs/contracts/events.md
Comment on lines +36 to +37
1. **Non-blocking callbacks:** Event callbacks are executed synchronously by the engine's worker goroutines. Consumers **must not** perform long-blocking operations in the callback. If processing requires heavy I/O, dispatch it to a channel or separate goroutine.
2. **Thread safety:** The `Device` pointer in `EventResult` points to a copied value, but consumers should avoid mutating it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The onEvent callback is invoked concurrently from multiple worker goroutines. It is crucial to explicitly document this behavior so that consumers know they must implement thread-safe callbacks when mutating shared state or updating UI components.

Suggested change
1. **Non-blocking callbacks:** Event callbacks are executed synchronously by the engine's worker goroutines. Consumers **must not** perform long-blocking operations in the callback. If processing requires heavy I/O, dispatch it to a channel or separate goroutine.
2. **Thread safety:** The `Device` pointer in `EventResult` points to a copied value, but consumers should avoid mutating it.
1. **Non-blocking callbacks:** Event callbacks are executed synchronously by the engine's worker goroutines. Consumers **must not** perform long-blocking operations in the callback. If processing requires heavy I/O, dispatch it to a channel or separate goroutine.
2. **Thread safety:** The `onEvent` callback is invoked concurrently from multiple worker goroutines. Consumers **must** ensure that the callback implementation is fully thread-safe (e.g., by using mutexes or channels) when mutating shared state or updating UI components. Additionally, while the `Device` pointer in `EventResult` points to a copied value, consumers should avoid mutating it.

@mendsec
mendsec merged commit f630082 into develop Jun 5, 2026
1 check passed
@mendsec
mendsec deleted the feature/m2-contracts branch June 21, 2026 13:05
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.

1 participant