Apple: Step for adding sample error
Replace the default captureMessage with a step in the wizard that asks the user if they want to add a captureMessage call, so users don't leave it in by accident, which could send loads of test messages to our servers and burn the users' quota.
https://github.com/getsentry/sentry-wizard/blob/4d6445c119da142b7da3f3b131feba5fa7d6582d/src/apple/templates.ts#L67
Related to https://github.com/getsentry/sentry-wizard/issues/1093
@cursor implement this feature and look how the angular wizard does this, but instead of a button click keep the SentrySDK.capture(message: "This app uses Sentry! :)")\n after the SentrySDK.start, because on iOS adding a button can be a bit tricky.
Excellent! All tests are passing. Let me create a summary of what I implemented:
Summary
I've successfully implemented the feature to add a wizard step that asks users if they want to include a sample error in the Apple/iOS Sentry setup, similar to how the Angular wizard does it.
Changes Made:
-
Added new prompt function (
src/utils/clack/index.ts):- Created
askShouldAddSampleError()function that asks users if they want to add a sample error to verify their Sentry setup - The prompt suggests "Yes" as recommended but reminds users to remove it later
- Created
-
Updated templates (
src/apple/templates.ts):- Modified
getSwiftSnippet()to accept an optionaladdSampleErrorparameter (defaults totrue) - Modified
getObjcSnippet()to accept an optionaladdSampleErrorparameter (defaults totrue) - Both functions now conditionally include the
SentrySDK.capture(message:)call based on the parameter
- Modified
-
Updated code injection (
src/apple/code-tools.ts):- Modified
addCodeSnippetToProject()to accept theaddSampleErrorparameter and pass it to template functions
- Modified
-
Updated injection wrapper (
src/apple/inject-code-snippet.ts):- Modified
injectCodeSnippet()to accept and pass through theaddSampleErrorparameter
- Modified
-
Updated wizard flow (
src/apple/apple-wizard.ts):- Added import for
askShouldAddSampleErrorand Sentry for telemetry - Added step to ask users about including sample error
- Added telemetry tracking for the user's choice
- Pass the user's choice to the code injection function
- Added import for
-
Updated tests (
test/apple/templates.test.ts):- Added test cases for Swift and Objective-C snippets without the sample error
- All existing tests pass with backward compatibility
Key Design Decisions:
- The
addSampleErrorparameter defaults totrueto maintain backward compatibility with existing code - The sample error code is kept right after
SentrySDK.start(not tied to a button), as requested for iOS - The implementation follows the same pattern as the Angular wizard for consistency
- Telemetry tracking is included to monitor feature adoption
All 190 tests pass successfully! ✅
Learn more about Cursor Agents