Skip to content

Conversation

Muhammed9991
Copy link

Add reportIfNil: Report unexpected nil values as issues

This PR introduces a new utility, reportIfNil, to the swift-issue-reporting library. It evaluates an optional value and reports an issue if the value is nil, using the existing IssueReporter infrastructure.


Motivation

While withErrorReporting handles thrown errors, there is currently no equivalent for reporting unexpected nil values — a common source of bugs in Swift.


Tests Included

Tests are split into focused cases for better clarity and maintainability:

  • ✅ Reports issue for nil value with default message
  • ✅ Reports issue for nil value with custom message
  • ✅ Does not report issue when value is non-nil

Related

Complements existing withErrorReporting functionality by offering a similar utility for handling optional values that shouldn't be nil.

@Muhammed9991
Copy link
Author

I can't assign anyone to this PR @stephencelis. So just tagging you

@stephencelis
Copy link
Member

@Muhammed9991 Sorry for the delay! Missed this.

Thanks for sharing. I think we want to keep the API surface area of Issue Reporting to be minimal and as close to the source Apple APIs as possible (in this case Issue.record vs. reportIssue). Since there's no precedent for this functionality in Swift Testing I think we'd prefer it being implemented outside the library. You could even package it up into its own library.

Let us know if anything is preventing you from doing this though!

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