Skip to content

fix(p2-json-errors): remove safe-but-flagged unwrap in is_type_id_value#82

Merged
brettdavies merged 1 commit into
devfrom
fix/p2-json-errors-line-192-unwrap
Jun 4, 2026
Merged

fix(p2-json-errors): remove safe-but-flagged unwrap in is_type_id_value#82
brettdavies merged 1 commit into
devfrom
fix/p2-json-errors-line-192-unwrap

Conversation

@brettdavies

Copy link
Copy Markdown
Owner

Summary

Addresses the json_errors.rs:192 finding from PR #80's dogfood run: the .unwrap() on trimmed.chars().next() inside is_type_id_value was provably safe (an is_empty() guard ten lines earlier guarantees at least one char), but the code-unwrap source audit pattern-matches on .unwrap() call expressions and surfaced it during self-dogfood.

Replaces the .unwrap() with a let-else that returns false, consistent with the function's "return false on any invalid input" pattern. Adds a comprehensive unit test (is_type_id_value_validates_json_shapes) covering all five non-string JSON value kinds (Number, Bool, Null, Array, Object), three valid identifier shapes (kebab-case, SCREAMING_SNAKE, snake_case), and three invalid string shapes (whitespace, period-separated, leading digit).

Changelog

Fixed

  • Fix code-unwrap self-dogfood finding at json_errors.rs:192: replace .unwrap() with a let-else returning false in is_type_id_value.

Type of Change

  • fix: Bug fix (non-breaking change which fixes an issue)

Related Issues/Stories

Testing

  • Unit tests added/updated
  • All tests passing

Test Summary:

  • cargo test: 848 passed, 2 ignored (8 suites). +1 new test is_type_id_value_validates_json_shapes in src/audits/behavioral/json_errors.rs.
  • cargo clippy --all-targets -- -Dwarnings: clean.
  • cargo fmt --check: clean.

Files Modified

Modified:

  • src/audits/behavioral/json_errors.rs: replace .unwrap() with let-else at line 192; add is_type_id_value_validates_json_shapes unit test.

Created:

  • None.

Renamed:

  • None.

Deleted:

  • None.

Breaking Changes

  • No breaking changes

Deployment Notes

  • No special deployment steps required

Checklist

  • Code follows project conventions and style guidelines
  • Commit messages follow Conventional Commits
  • Self-review of code completed
  • Tests added/updated and passing
  • No new warnings or errors introduced
  • Changes are backward compatible

The `.unwrap()` on `trimmed.chars().next()` was provably safe given the
prior `is_empty()` guard, but the `code-unwrap` audit pattern-matches on
`.unwrap()` call expressions and reported it on self-dogfood. Replace
with a `let-else` returning `false` (the function's canonical
invalid-input response). One line of substance plus a comprehensive
unit test covering Number/Bool/Null/Array/Object/string-shape variants.

Surfaced during PR #80 review.
@brettdavies brettdavies merged commit 4372857 into dev Jun 4, 2026
8 checks passed
@brettdavies brettdavies deleted the fix/p2-json-errors-line-192-unwrap branch June 4, 2026 16:48
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