Skip to content

Add maui errors list command for error code introspection#202

Draft
rmarinho wants to merge 2 commits into
mainfrom
cli/errors-list
Draft

Add maui errors list command for error code introspection#202
rmarinho wants to merge 2 commits into
mainfrom
cli/errors-list

Conversation

@rmarinho
Copy link
Copy Markdown
Member

Summary

Adds the \maui errors list [--json]\ command that emits the registered error code catalogue, enabling AI agents and IDE consumers to statically verify they handle every \MauiToolException\ error code.

Changes

  • \ErrorCodeDescriptor.cs\ — model record with snake_case JSON properties
  • \ErrorCodeCatalogue.cs\ — static catalogue covering all 23 registered error codes
  • \ErrorsCommands.cs\ — \maui errors list [--category] [--prefix] [--json]\ command
  • \MauiCliJsonContext.cs\ — added 3 [JsonSerializable]\ entries
  • \Program.cs\ — registered \ErrorsCommands.Create()\
  • \ErrorsCatalogueTests.cs\ — 17 unit tests including reflection-based drift detection

Usage

\
maui errors list
maui errors list --category platform
maui errors list --prefix E21
maui errors list --json
\\

The \Catalogue_CoversEveryConstantInErrorCodes\ test uses reflection on \ErrorCodes\ to catch future drift when new codes are added.

Adds ErrorCodeDescriptor model, ErrorCodeCatalogue static catalogue,
and the 'maui errors list [--category] [--prefix] [--json]' command.

The catalogue covers all 23 registered error codes in ErrorCodes.cs.
The reflection-based test Catalogue_CoversEveryConstantInErrorCodes
will catch future drift when new codes are added.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Expert Code Review — PR #202

Methodology: 3 independent reviewers with adversarial consensus (2-reviewer fallback — 1 reviewer's detailed output was unavailable)

Result: 1 finding posted as inline comment (1 minor)

CI Status

✅ Build passes on both macOS and Windows

Test Coverage

✅ PR includes 17 unit tests with reflection-based drift detection covering the catalogue, filters, serialization, and command registration

Discarded Findings (single-reviewer only, no consensus)

Reviewer Severity File Finding
2 🟡 ErrorsCommands.cs:52 SpectreOutputFormatter downcast silently produces no output for non-Spectre formatters
3 🟡 ErrorCodeCatalogue.cs:36 Public API exposes mutable shared array instance via IReadOnlyList over ErrorCodeDescriptor[]
2 🟢 MauiCliJsonContext.cs List<ErrorCodeDescriptor> registered but not ErrorCodeDescriptor[] — potential AOT issue if array serialized directly
3 🟢 ErrorsCatalogueTests.cs:55 Drift test is one-directional (catches missing entries but not stale/removed ones)
2 🟢 ErrorsCatalogueTests.cs:90 Case-insensitivity tests compare counts not actual item sets

Generated by Expert Code Review · 3 independent reviewers with adversarial consensus

Generated by Expert Code Review (auto) for issue #202 · ● 7.5M ·

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Expert Review — maui errors list Command

Good addition overall. The reflection-based drift test (Catalogue_CoversEveryConstantInErrorCodes) is an excellent pattern. Two moderate issues worth addressing before merge:

Findings

# Severity File Line Issue Recommendation
1 🟡 MODERATE ErrorsCommands.cs 50 Non-Spectre formatter in non-JSON mode silently produces zero output and returns success. Add fallback else branch (plain-text output or error).
2 🟡 MODERATE ErrorsCommands.cs 33–37 --category and --prefix supplied together silently ignores --prefix with no warning. Either enforce mutual exclusivity with an error, or compose both filters (AND semantics).
3 🟡 MODERATE ErrorsCommands.cs 39–41 JSON mode emits {"codes":[],"count":0} for empty results with no warning, while non-JSON mode prints a warning. Asymmetric UX for consumers. Document or harmonize behavior across output modes.
4 🟢 MINOR ErrorCodeCatalogue.cs 38–42 ByCategory/ByPrefix allocate a new list per call. Fine for CLI use; consider lazy IEnumerable if reused in hot paths.
5 🟢 MINOR MauiCliJsonContext.cs 50 List<ErrorCodeDescriptor> registration appears unused (property is IReadOnlyList). Remove or retain intentionally — no runtime impact.

Generated by Expert Code Review (auto) for issue #202 · ● 7.5M

Comment on lines +33 to +37
IReadOnlyList<ErrorCodeDescriptor> codes = category is not null
? ErrorCodeCatalogue.ByCategory(category)
: prefix is not null
? ErrorCodeCatalogue.ByPrefix(prefix)
: ErrorCodeCatalogue.All;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 MINOR · Consensus: 2/2 reviewers

--prefix is silently discarded when --category is also supplied.

maui errors list --category platform --prefix E21 silently ignores --prefix and returns all platform errors instead of only Android codes. The user receives no indication that one filter was dropped.

Suggestion: Either make the options mutually exclusive with a validation error, or AND the filters together:

IReadOnlyList<ErrorCodeDescriptor> codes = ErrorCodeCatalogue.All
    .Where(d => category is null || d.Category.Equals(category, StringComparison.OrdinalIgnoreCase))
    .Where(d => prefix is null || d.Code.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
    .ToList();

Previously --prefix was silently ignored when --category was supplied.
Now filters apply intersectionally: --category narrows first, --prefix
refines further. Resolves PR #202 minor finding.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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