Skip to content

feat: functional_status_codes v3.2.0#124

Merged
tsinis merged 8 commits intomainfrom
feat/3.2.0
Mar 11, 2026
Merged

feat: functional_status_codes v3.2.0#124
tsinis merged 8 commits intomainfrom
feat/3.2.0

Conversation

@tsinis
Copy link
Copy Markdown
Owner

@tsinis tsinis commented Mar 9, 2026

Description

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 🧪 Tests
  • 📝 Documentation
  • ⚙️ CI/CD or GitHub Workflow configuration change
  • 📦 Dependencies update

Summary by CodeRabbit

  • New Features

    • Added isError API to detect 400–599 status codes
    • Packaged AI documentation, prompts and config for extension support
  • Bug Fixes

    • Improved null-handling in status-code mapping paths
    • Refined HTTP status-code pattern to match 100–599 and related behavior fixes
  • Documentation

    • Added API reference, functional patterns guide, and usage prompts
    • Removed trailing whitespace and License section from README
  • Tests

    • Added/updated tests for isError and regex/pattern behavior
  • Chores

    • Bumped package version to 3.2.0 and updated CHANGELOG.md

tsinis added 2 commits March 9, 2026 21:53
- Introduced `isError` getter for error checking on HTTP status codes.
- Packaged AI assets for enhanced coding agent support.
- Fixed various issues including null checks and regex patterns.
- Updated documentation for clarity on handler priorities.
Add comprehensive documentation for API reference, functional patterns,
and prompts related to handling HTTP responses and caching strategies.
github-actions[bot]
github-actions bot previously approved these changes Mar 9, 2026
@github-actions github-actions bot added feature enhancement New feature or request D-7 labels Mar 9, 2026
- Updated `StatusCode.pattern` and `StatusCode.regExp` to match only
  valid HTTP status codes (100–599) instead of any three-digit number.
github-actions[bot]
github-actions bot previously approved these changes Mar 9, 2026
@tsinis
Copy link
Copy Markdown
Owner Author

tsinis commented Mar 9, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

Warning

Rate limit exceeded

@tsinis has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 38 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d090c630-cd93-42b6-a058-0e7e427c5c09

📥 Commits

Reviewing files that changed from the base of the PR and between 2ca9fe9 and 7a61afa.

📒 Files selected for processing (3)
  • extension/mcp/resources/api_reference.md
  • extension/mcp/resources/patterns.md
  • lib/src/status_code.dart
📝 Walkthrough

Walkthrough

Adds release 3.2.0: public isError getter, null-check optimizations in mapping helpers, tighter StatusCode regex (100–599) and small random() change, new extension/mcp/ docs and prompts, README/license removal, and accompanying tests and changelog updates.

Changes

Cohort / File(s) Summary
Version & Changelog
pubspec.yaml, CHANGELOG.md
Bumped version to 3.2.0 and added changelog entries for new features, fixes, and docs.
Repository docs
README.md
Removed trailing blank lines and the License section (FOSSA badge removed).
MCP extension — config & prompts
extension/mcp/config.yaml, extension/mcp/prompts/cache_strategy.md, extension/mcp/prompts/handle_response.md
Added MCP config and two prompt templates (cache strategy, handle response) with argument metadata and file pointers.
MCP extension — resources
extension/mcp/resources/api_reference.md, extension/mcp/resources/patterns.md
Added API reference and functional patterns guide documenting StatusCode usage and examples (documentation only).
Core: NumStatusCode extension
lib/src/num_status_code_extension.dart
Added public bool get isError on T? num extension; renamed private constant _outSideOfRangeMessage_outsideOfRangeMessage; inserted early null handling in mapping/when helpers and clarified handler-priority docs.
Core: StatusCode internals
lib/src/status_code.dart
Tightened pattern/regExp to match 100–599 using lookarounds, updated docs/counts, and replaced List.unmodifiable(from) use in random() with a concrete list selection.
Tests
test/src/num_status_code_extension_test.dart, test/src/status_code_test.dart
Added isError tests; expanded tests for pattern/regExp behavior and updated an edge-case test name/comments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete; only the 'Type of Change' section is filled out while the required 'Description' section with details and related issues is empty. Fill in the 'Description' section with details about the changes, rationale, and any related issues; provide context for the new features and bug fixes included in v3.2.0.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: releasing version 3.2.0 with new features, bug fixes, refactors, and documentation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates functional_status_codes to v3.2.0, adding a small API convenience (isError), tightening status-code parsing behavior, and shipping MCP-compatible packaged AI assets (resources + prompts) intended to help agents generate idiomatic usage of the library.

Changes:

  • Bump package version to 3.2.0 and add a detailed CHANGELOG entry for the release.
  • Update core helpers: add num?.isError, tighten StatusCode.pattern to 100–599, and remove an unnecessary allocation in StatusCode.random().
  • Add MCP packaged AI assets under extension/mcp/ (resources, prompts, and config).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pubspec.yaml Version bump to 3.2.0.
lib/src/status_code.dart Regex pattern tightened to 100–599; small random() implementation tweak; doc count updated.
lib/src/num_status_code_extension.dart Add isError, clarify handler priority docs, and minor null/perf tweak in registered-mapping path.
extension/mcp/resources/patterns.md New functional usage patterns guide for agents/users.
extension/mcp/resources/api_reference.md New API cheat-sheet for agents/users.
extension/mcp/prompts/handle_response.md New agent prompt to generate response-handling code.
extension/mcp/prompts/cache_strategy.md New agent prompt to derive caching strategies from status codes.
extension/mcp/config.yaml Registers MCP resources and prompts.
README.md Removes trailing License section block from the end of the README.
CHANGELOG.md Adds v3.2.0 release notes covering new API, fixes, and docs.
Comments suppressed due to low confidence (1)

lib/src/status_code.dart:710

  • The regExp getter documentation below still describes the old \d{3} behavior (“three consecutive digits” / “matches any three-digit number”), but pattern was changed to [1-5]\d{2}. Please update the regExp doc comment to match the new range-limited pattern and examples so users aren’t misled.
  static const pattern = r'[1-5]\d{2}';

  /// A getter that returns a [RegExp] object configured with a pattern to match
  /// three consecutive digits, typically representing an HTTP status code.
  ///

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

- Updated API reference with clearer examples for StatusCode usage.
- Improved patterns guide to reflect changes in response handling.
- Added tests for error handling in NumStatusCodeExtension.
github-actions[bot]
github-actions bot previously approved these changes Mar 9, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/src/status_code.dart (1)

1253-1257: ⚠️ Potential issue | 🟠 Major

Snapshot from before sampling.

This now walks non-list iterables twice: once for length, then again for elementAt(). For lazy or stateful iterables, those two passes can see different data, so the sampled index no longer corresponds to a stable population. The previous snapshotting behavior was safer and matches the documented “any iterable type” support.

🔧 Suggested fix
   static StatusCode random({
     Iterable<StatusCode> from = values,
     Random? random,
   }) {
-    assert(from.isNotEmpty, 'The provided `from` iterable must not be empty');
-    final elementAt = (random ?? Random()).nextInt(from.length);
-
-    // ignore: avoid-unsafe-collection-methods, length is guaranteed to be > 0.
-    return from.elementAt(elementAt);
+    final snapshot = List<StatusCode>.unmodifiable(from);
+    assert(
+      snapshot.isNotEmpty,
+      'The provided `from` iterable must not be empty',
+    );
+    final index = (random ?? Random()).nextInt(snapshot.length);
+    return snapshot[index];
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/src/status_code.dart` around lines 1253 - 1257, The current code reads
the iterable `from` twice (for `length` and for `elementAt`), which can produce
inconsistent results for lazy/stateful iterables; snapshot `from` into a stable
collection first (e.g., assign a local List like `snapshot = from is List ? from
: from.toList()`), assert `snapshot.isNotEmpty`, compute the random index
against `snapshot.length`, and return `snapshot.elementAt(elementAt)` (or
`snapshot[elementAt]`) so both length and element access operate on the same
materialized population; update the `assert` and the use of `elementAt`/`length`
to use this snapshot variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@extension/mcp/prompts/cache_strategy.md`:
- Around line 30-40: The snippet calls whenConstOrNull on a raw int; convert the
rawCode to the StatusCode type first by calling toRegisteredStatusCode() (e.g.,
assign statusCode = rawCode.toRegisteredStatusCode()), then call whenConstOrNull
on that StatusCode (use a nullable call if toRegisteredStatusCode can return
null, e.g., statusCode?.whenConstOrNull(...)) to produce ttl; apply the same
change for the other occurrence that also calls whenConstOrNull on a numeric
value.

In `@extension/mcp/prompts/handle_response.md`:
- Around line 38-41: Update the prompt guidance so it no longer describes the
whenConst* APIs as callback-based: explicitly state that whenConstStatusCode and
whenConstOrNull accept direct constant values (and should be used with const),
not closures, and instruct agents to avoid generating () => branches; preserve
the recommendation to prefer const values for constant returns and to use ?. /
?? and .isSuccess/.isError/.isCacheable instead of manual null-checks or numeric
ranges.

In `@extension/mcp/resources/api_reference.md`:
- Around line 136-144: The examples use incorrect parameters for the `num`
extension APIs: `whenConstStatusCode` does not accept an `orElse` argument, and
`mapToRegisteredStatusCode` does not take `mapper`/`orElse` but instead accepts
category callback keys (`isInformational`, `isSuccess`, `isRedirection`,
`isClientError`, `isServerError`). Update the
`response.statusCode.whenConstStatusCode` example to only pass the direct value
arguments (remove `orElse`), and update the
`response.statusCode.mapToRegisteredStatusCode` example to pass callbacks for
each category (e.g. `isInformational: () => 'info'`, etc.) so the examples match
the actual `whenConstStatusCode` and `mapToRegisteredStatusCode` signatures.

In `@extension/mcp/resources/patterns.md`:
- Around line 188-200: The tests call helpers with the wrong signatures: provide
a parseBody callback when calling handleResponse (e.g., pass a simple closure
matching the required parseBody param) and mark the cache test as async and
await the async fetchAndCache call; update the test that uses fetchAndCache to
be declared async and change fetchAndCache('key', () async =>
Response(statusCode: code)) to await fetchAndCache(...). Target the failing
calls to handleResponse(...) and fetchAndCache(...) in the tests so the correct
argument types and async/await usage are applied.
- Around line 86-96: The documentation example uses whenConstStatusCode with an
orElse argument which is invalid; update the snippet to call
whenConstStatusCodeOrNull instead (keep the same named parameters
isInformational, isSuccess, isRedirection, isClientError, isServerError and the
orElse value) so the example matches the correct method signature.
- Around line 7-23: The example's handleResponse declares Future<T?> but returns
a synchronous value from statusCode.maybeMapStatusCode; change the signature to
T? handleResponse<T>(int statusCode, T Function() parseBody) (or alternatively
make the function async and return Future.value(...)) and add the missing import
for dart:io so HttpException resolves; ensure the existing import for
StatusCode/functional_status_codes remains. Reference: handleResponse,
maybeMapStatusCode, HttpException, StatusCode.

In `@lib/src/status_code.dart`:
- Around line 686-706: The regex pattern constant pattern currently uses an
unanchored '[1-5]\d{2}', which allows matching substrings inside longer numbers
(e.g., '6100' → '100') and thus causes tryParse to accept invalid input; change
the pattern to be anchored to match exactly a three-digit HTTP status (e.g., use
'^' and '$' around the existing class), ensure tryParse uses that anchored
pattern, and update the regExp documentation text below (mentions '\d{3}' / "any
three-digit number") to explicitly state the pattern is anchored and matches
only a full three-digit status code in the 100–599 range (no substring matches).

---

Outside diff comments:
In `@lib/src/status_code.dart`:
- Around line 1253-1257: The current code reads the iterable `from` twice (for
`length` and for `elementAt`), which can produce inconsistent results for
lazy/stateful iterables; snapshot `from` into a stable collection first (e.g.,
assign a local List like `snapshot = from is List ? from : from.toList()`),
assert `snapshot.isNotEmpty`, compute the random index against
`snapshot.length`, and return `snapshot.elementAt(elementAt)` (or
`snapshot[elementAt]`) so both length and element access operate on the same
materialized population; update the `assert` and the use of `elementAt`/`length`
to use this snapshot variable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 72fa8006-23cd-4de5-8a29-a10f05437e10

📥 Commits

Reviewing files that changed from the base of the PR and between a2b268f and 75dff9b.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • README.md
  • extension/mcp/config.yaml
  • extension/mcp/prompts/cache_strategy.md
  • extension/mcp/prompts/handle_response.md
  • extension/mcp/resources/api_reference.md
  • extension/mcp/resources/patterns.md
  • lib/src/num_status_code_extension.dart
  • lib/src/status_code.dart
  • pubspec.yaml
💤 Files with no reviewable changes (1)
  • README.md

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/src/status_code.dart (1)

1250-1258: 🧹 Nitpick | 🔵 Trivial

Avoid double-traversing arbitrary iterables in random().

This method advertises Iterable<StatusCode>, and test/src/status_code_test.dart:165-180 passes a lazy where(...).take(5) iterable. from.length plus from.elementAt(...) walks that iterable twice and re-evaluates the pipeline. Materialize once when from is not already a list.

Refactor sketch
 static StatusCode random({
   Iterable<StatusCode> from = values,
   Random? random,
 }) {
-  assert(from.isNotEmpty, 'The provided `from` iterable must not be empty');
-  final elementAt = (random ?? Random()).nextInt(from.length);
-
-  // ignore: avoid-unsafe-collection-methods, length is guaranteed to be > 0.
-  return from.elementAt(elementAt);
+  final codes =
+      from is List<StatusCode> ? from : from.toList(growable: false);
+  assert(codes.isNotEmpty, 'The provided `from` iterable must not be empty');
+  final index = (random ?? Random()).nextInt(codes.length);
+  return codes[index];
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/src/status_code.dart` around lines 1250 - 1258, The StatusCode.random
method currently traverses the provided Iterable twice (using from.length and
from.elementAt) which can re-evaluate lazy pipelines; to fix, materialize the
iterable once when it's not already a List: inside StatusCode.random create a
local variable (e.g., final elements = from is List<StatusCode> ? from :
from.toList()), keep the assert against elements.isNotEmpty, then use
elements.length and return elements[elementAt]; this ensures single traversal
and correct indexing for lazy iterables.
♻️ Duplicate comments (4)
extension/mcp/resources/patterns.md (2)

86-96: ⚠️ Potential issue | 🟠 Major

Use the nullable const variant here.

whenConstStatusCode does not accept orElse, so this snippet will not compile. Switch the example to whenConstStatusCodeOrNull if you want a fallback value.

Suggested doc fix
-Category-level const mapping via `whenConstStatusCode`:
+Category-level const mapping via `whenConstStatusCodeOrNull`:

 ```dart
-final label = rawCode.whenConstStatusCode(
+final label = rawCode.whenConstStatusCodeOrNull(
   isInformational: 'informational',
   isSuccess: 'success',
   isRedirection: 'redirect',
   isClientError: 'client error',
   isServerError: 'server error',
   orElse: 'unknown',
 );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extension/mcp/resources/patterns.md` around lines 86 - 96, The example uses
whenConstStatusCode with an orElse (which is invalid); change the call on
rawCode to the nullable variant whenConstStatusCodeOrNull and either provide the
fallback by coalescing the result (e.g., ?? 'unknown') or remove the orElse
param, so update the label assignment to call whenConstStatusCodeOrNull and
handle null fallback externally.

188-200: ⚠️ Potential issue | 🟠 Major

These test snippets still do not match the helpers defined above.

handleResponse needs the parseBody callback, fetchAndCache must be awaited from an async test, and the expectations are wrong for the current helper: it only returns null for 404, while StatusCode.custom(999) violates the constructor range and would hit orElse/throw instead.

Also applies to: 211-216

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extension/mcp/resources/patterns.md` around lines 188 - 200, Update the tests
to match the helper signatures and valid StatusCode ranges: call handleResponse
with a parseBody callback (e.g., handleResponse(code, parseBody: () => ...)) and
change the second test to be async and await fetchAndCache('key', () async =>
Response(statusCode: code)); also adjust expectations so you only assert null
for the specific 404 case (not every client error) and ensure StatusCode.random
is constrained to valid ranges (avoid constructing invalid codes like
StatusCode.custom(999) that hit orElse/throw) or replace random usage with
explicit valid codes from StatusCode.clientErrorCodes and
StatusCode.cacheableCodes.
extension/mcp/resources/api_reference.md (1)

133-153: ⚠️ Potential issue | 🟠 Major

These API examples still use signatures the package does not ship.

whenConstStatusCode has no orElse parameter, and mapToRegisteredStatusCode does not accept mapper/orElse. As written, both examples are uncompilable.

Possible doc direction
-// Const-value variant (no closures — direct values)
-response.statusCode.whenConstStatusCode(
+// Const-value variant with fallback
+response.statusCode.whenConstStatusCodeOrNull(
   isInformational: 'info',
   isSuccess: 'ok',
   isRedirection: 'redirect',
   isClientError: 'client error',
   isServerError: 'server error',
   orElse: 'unknown',
 )
-// Convert then map in one step
-response.statusCode.mapToRegisteredStatusCode(
-  mapper: (statusCode) => statusCode.reason,
-  orElse: (raw) => 'Unknown: $raw',
-)
+// Convert, then read the registered reason when available
+response.statusCode.toRegisteredStatusCode()?.reason ??
+    'Unknown: ${response.statusCode}'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extension/mcp/resources/api_reference.md` around lines 133 - 153, The docs
use wrong function signatures: update the examples to match the actual API for
whenConstStatusCode, whenConstStatusCodeOrNull, and mapToRegisteredStatusCode by
removing non-existent named parameters and using the real parameter
names/positional form; specifically, remove the orElse named argument from
whenConstStatusCode examples, show whenConstStatusCodeOrNull usage that handles
a nullable return (e.g., check for null instead of passing orElse), and replace
the mapToRegisteredStatusCode example to call it with the actual parameter shape
the package exposes (use the real parameter name or positional lambda and the
correct fallback mechanism the function provides) so the snippets compile as-is.
lib/src/status_code.dart (1)

706-734: ⚠️ Potential issue | 🟠 Major

tryParse() still accepts inner substrings of larger numbers.

With an unanchored [1-5]\d{2} and firstMatch, inputs like 6100 or 2000 can still parse as 100 or 200. If substring extraction from prose is intentional, tryParse needs a non-digit boundary check instead of using the first regex hit blindly.

Also applies to: 769-773

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/src/status_code.dart` around lines 706 - 734, The regExp currently uses
an unanchored pattern '[1-5]\d{2}', which allows matching substrings inside
larger numbers (e.g., '6100' -> '100'); update the pattern used by RegExp (and
the related usage in tryParse) to require non-digit boundaries so the match is
not part of a larger numeric token (e.g., use lookarounds like
(?<!\d)([1-5]\d{2})(?!\d) or equivalent) and adjust tryParse to extract the
captured group rather than blindly taking a firstMatch that could be a
substring; apply the same fix to the other occurrence noted (around the tryParse
implementation at lines ~769-773).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@extension/mcp/resources/api_reference.md`:
- Around line 33-42: The docs claim StatusCode.officialCodes is the
"IANA-registered subset" but the implementation of StatusCode.officialCodes
includes unofficial entries (e.g., StatusCode.siteIsFrozenHttp530 and
StatusCode.nginxClientClosedRequestHttp499); either update the documentation
text in the API reference to remove the strict "IANA-registered" wording or
modify the StatusCode.officialCodes collection to remove non-IANA codes (scan
StatusCode.officialCodes in status_code.dart and drop any entries not officially
IANA-registered such as siteIsFrozenHttp530 and
nginxClientClosedRequestHttp499), then run tests/lint to ensure no references
break and update the enum/collection comment to reflect the chosen behavior.

---

Outside diff comments:
In `@lib/src/status_code.dart`:
- Around line 1250-1258: The StatusCode.random method currently traverses the
provided Iterable twice (using from.length and from.elementAt) which can
re-evaluate lazy pipelines; to fix, materialize the iterable once when it's not
already a List: inside StatusCode.random create a local variable (e.g., final
elements = from is List<StatusCode> ? from : from.toList()), keep the assert
against elements.isNotEmpty, then use elements.length and return
elements[elementAt]; this ensures single traversal and correct indexing for lazy
iterables.

---

Duplicate comments:
In `@extension/mcp/resources/api_reference.md`:
- Around line 133-153: The docs use wrong function signatures: update the
examples to match the actual API for whenConstStatusCode,
whenConstStatusCodeOrNull, and mapToRegisteredStatusCode by removing
non-existent named parameters and using the real parameter names/positional
form; specifically, remove the orElse named argument from whenConstStatusCode
examples, show whenConstStatusCodeOrNull usage that handles a nullable return
(e.g., check for null instead of passing orElse), and replace the
mapToRegisteredStatusCode example to call it with the actual parameter shape the
package exposes (use the real parameter name or positional lambda and the
correct fallback mechanism the function provides) so the snippets compile as-is.

In `@extension/mcp/resources/patterns.md`:
- Around line 86-96: The example uses whenConstStatusCode with an orElse (which
is invalid); change the call on rawCode to the nullable variant
whenConstStatusCodeOrNull and either provide the fallback by coalescing the
result (e.g., ?? 'unknown') or remove the orElse param, so update the label
assignment to call whenConstStatusCodeOrNull and handle null fallback
externally.
- Around line 188-200: Update the tests to match the helper signatures and valid
StatusCode ranges: call handleResponse with a parseBody callback (e.g.,
handleResponse(code, parseBody: () => ...)) and change the second test to be
async and await fetchAndCache('key', () async => Response(statusCode: code));
also adjust expectations so you only assert null for the specific 404 case (not
every client error) and ensure StatusCode.random is constrained to valid ranges
(avoid constructing invalid codes like StatusCode.custom(999) that hit
orElse/throw) or replace random usage with explicit valid codes from
StatusCode.clientErrorCodes and StatusCode.cacheableCodes.

In `@lib/src/status_code.dart`:
- Around line 706-734: The regExp currently uses an unanchored pattern
'[1-5]\d{2}', which allows matching substrings inside larger numbers (e.g.,
'6100' -> '100'); update the pattern used by RegExp (and the related usage in
tryParse) to require non-digit boundaries so the match is not part of a larger
numeric token (e.g., use lookarounds like (?<!\d)([1-5]\d{2})(?!\d) or
equivalent) and adjust tryParse to extract the captured group rather than
blindly taking a firstMatch that could be a substring; apply the same fix to the
other occurrence noted (around the tryParse implementation at lines ~769-773).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 61effb88-8a0e-4b7a-a829-cc7be158f59b

📥 Commits

Reviewing files that changed from the base of the PR and between 75dff9b and 1120102.

📒 Files selected for processing (5)
  • extension/mcp/resources/api_reference.md
  • extension/mcp/resources/patterns.md
  • lib/src/num_status_code_extension.dart
  • lib/src/status_code.dart
  • test/src/num_status_code_extension_test.dart

- Clarified usage of `whenConstOrNull` and `toRegisteredStatusCode()`
- Improved regex pattern for status code matching with negative lookarounds
- Enhanced test cases for regex pattern validation
github-actions[bot]
github-actions bot previously approved these changes Mar 9, 2026
- Clarified the description of officialCodes in api_reference.md
- Updated tests in patterns.md to focus on specific status codes
- Improved list creation in status_code.dart for better performance
github-actions[bot]
github-actions bot previously approved these changes Mar 9, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
extension/mcp/resources/api_reference.md (1)

33-42: ⚠️ Potential issue | 🟡 Minor

Documentation inaccuracy: officialCodes includes unofficial codes.

The comment describes StatusCode.officialCodes as the "IANA-registered subset", but the actual implementation in lib/src/status_code.dart includes unofficial codes such as siteIsFrozenHttp530, nginxClientClosedRequestHttp499, and other vendor-specific codes.

Consider either:

  1. Updating the documentation to accurately describe what the collection contains
  2. Or renaming/refactoring the collection in the source code
🔧 Suggested documentation fix
-StatusCode.officialCodes       // IANA-registered subset
+StatusCode.officialCodes       // Commonly recognized codes (includes some vendor-specific)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extension/mcp/resources/api_reference.md` around lines 33 - 42, Update the
inaccurate doc comment for StatusCode.officialCodes to reflect that it contains
both IANA-registered and vendor/unofficial codes (e.g., "IANA-registered and
vendor-specific/unofficial codes"), or alternatively rename/refactor the
collection in the code (StatusCode.officialCodes) to a clearer identifier (e.g.,
StatusCode.officialAndVendorCodes) and update all references and documentation
to match; locate the symbol StatusCode.officialCodes (and related collections
like StatusCode.informationalCodes, StatusCode.successCodes) and change the doc
string in the API reference or the collection name in the implementation and
adjust usages accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@extension/mcp/prompts/cache_strategy.md`:
- Line 1: Add a top-level Markdown heading to the prompt template to satisfy
markdownlint: insert a line like "# Cache Strategy Prompt" (or similar) above
the existing content that begins "Derive a caching strategy for HTTP status code
**{{status_code}}**..." so the file contains a clear top-level heading while
preserving the Mustache variable {{status_code}} and the rest of the prompt
text.

In `@lib/src/status_code.dart`:
- Around line 686-707: Update the doc comment around the static const pattern to
avoid the flagged word "lookarounds": replace occurrences of "lookarounds" with
"lookahead/lookbehind assertions" (or similar phrasing) in the documentation for
pattern (and any other comments referencing the regex), ensuring references to
RegExp, StatusCode, and maybeFromCode remain intact and wording remains clear;
do not add code, only change the comment text so the spellchecker passes.

---

Duplicate comments:
In `@extension/mcp/resources/api_reference.md`:
- Around line 33-42: Update the inaccurate doc comment for
StatusCode.officialCodes to reflect that it contains both IANA-registered and
vendor/unofficial codes (e.g., "IANA-registered and vendor-specific/unofficial
codes"), or alternatively rename/refactor the collection in the code
(StatusCode.officialCodes) to a clearer identifier (e.g.,
StatusCode.officialAndVendorCodes) and update all references and documentation
to match; locate the symbol StatusCode.officialCodes (and related collections
like StatusCode.informationalCodes, StatusCode.successCodes) and change the doc
string in the API reference or the collection name in the implementation and
adjust usages accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 31b8e9de-2a39-4d98-8204-0c69326dda99

📥 Commits

Reviewing files that changed from the base of the PR and between 1120102 and 2ca9fe9.

📒 Files selected for processing (6)
  • extension/mcp/prompts/cache_strategy.md
  • extension/mcp/prompts/handle_response.md
  • extension/mcp/resources/api_reference.md
  • extension/mcp/resources/patterns.md
  • lib/src/status_code.dart
  • test/src/status_code_test.dart

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 9, 2026
Updated the comments to clarify the use of negative look-ahead and
look-behind assertions in the regex pattern for matching HTTP status codes.
github-actions[bot]
github-actions bot previously approved these changes Mar 9, 2026
The pattern now specifies negative look-ahead and look-behind assertions
to ensure accurate extraction of HTTP status codes from text.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.57%. Comparing base (b3c6147) to head (7a61afa).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
lib/src/num_status_code_extension.dart 33.33% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #124   +/-   ##
=======================================
  Coverage   99.56%   99.57%           
=======================================
  Files           3        3           
  Lines        1395     1397    +2     
=======================================
+ Hits         1389     1391    +2     
  Misses          6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tsinis tsinis merged commit fdffb78 into main Mar 11, 2026
15 of 16 checks passed
@tsinis tsinis deleted the feat/3.2.0 branch March 11, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

D-7 enhancement New feature or request feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants