Skip to content

Replace assert() with exceptions for release-mode safety#30

Merged
Harry-Chen merged 1 commit intonfcim:masterfrom
klaasdannen:fix/assert-to-exceptions
Mar 13, 2026
Merged

Replace assert() with exceptions for release-mode safety#30
Harry-Chen merged 1 commit intonfcim:masterfrom
klaasdannen:fix/assert-to-exceptions

Conversation

@klaasdannen
Copy link
Contributor

Summary

  • assert() statements in ndef.dart and record.dart are stripped in Dart release builds, silently disabling all NDEF flag validation (MB, ME, CF) and TNF/type-length checks in production
  • Replaced with FormatException for malformed NDEF data (invalid flags, wrong type lengths)
  • Replaced with RangeError for invalid TNF values in NDEFRecordFlags.encode()

Files changed

  • lib/ndef.dart -- MB/ME/CF flag validation in decodeRawNdefMessage()
  • lib/record.dart -- TNF range check in NDEFRecordFlags.encode(), type/id/payload length checks in decodeStream()

Test plan

  • Existing tests pass unchanged
  • In release mode (dart compile exe), decoding malformed NDEF data now correctly throws instead of silently accepting it

assert() statements are stripped in Dart release builds, meaning all
NDEF flag validation (MB, ME, CF) and TNF/type-length checks silently
disappear in production. Replaced with FormatException for malformed
NDEF data and RangeError for invalid TNF values, so errors are caught
regardless of build mode.
@Harry-Chen Harry-Chen merged commit eee8019 into nfcim:master Mar 13, 2026
2 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