Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Change fastlane injection to `sentry_debug_files_upload` instead of `sentry_cli` ([#1125](https://github.com/getsentry/sentry-wizard/pull/1125))

## 6.8.0

### Features
Expand Down
6 changes: 5 additions & 1 deletion src/apple/fastlane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ function addSentryToLane(
project: string,
): string {
const laneContent = content.slice(lane.index, lane.index + lane.length);
const sentryCLIMatch = /sentry_cli\s*\([^)]+\)/gim.exec(laneContent);
const sentryCLIMatch = /(\n\s+)sentry_debug_files_upload\s*\([^)]+\)/gim.exec(
Copy link

Choose a reason for hiding this comment

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

Bug: The addSentryToLane function fails to replace sentry_cli with sentry_debug_files_upload, leading to duplicate Sentry calls.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The addSentryToLane function's regex sentryCLIMatch = /(\n\s+)sentry_debug_files_upload\s*\([^)]+\)/gim.exec(laneContent); on line 82 only matches sentry_debug_files_upload. If a user's Fastfile contains the old sentry_cli function, this regex will not match. This causes the code to insert a new sentry_debug_files_upload block without removing the existing sentry_cli block, resulting in a misconfigured Fastfile with both old and new Sentry calls.

💡 Suggested Fix

Update the regex in addSentryToLane to match both sentry_cli and sentry_debug_files_upload, or add logic to explicitly remove sentry_cli before inserting the new sentry_debug_files_upload block.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/apple/fastlane.ts#L82

Potential issue: The `addSentryToLane` function's regex `sentryCLIMatch =
/(\n\s+)sentry_debug_files_upload\s*\([^)]+\)/gim.exec(laneContent);` on line 82 only
matches `sentry_debug_files_upload`. If a user's Fastfile contains the old `sentry_cli`
function, this regex will not match. This causes the code to insert a new
`sentry_debug_files_upload` block without removing the existing `sentry_cli` block,
resulting in a misconfigured Fastfile with both old and new Sentry calls.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4205707

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is better than replacing sentry_cli as it could still be that users correctly use an older fastlane plugin version where it is set up. Happy for feedback on this one.

Copy link
Member

Choose a reason for hiding this comment

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

What bout matching on both sentry_cli and sentry_debug_files_upload?

Copy link
Member Author

Choose a reason for hiding this comment

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

To rephrase: I would not try to migrate sentry_cli to sentry_debug_files_upload because it might not be correct. By only matching sentry_debug_files_upload we are adding the code relevant for the user to the Fastfile, without touching the existing one.

Copy link
Member

Choose a reason for hiding this comment

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

l: The const sentryCLIMatch now matches the sentry_debug_files_upload. I guess the variable name should reflect that.

laneContent,
);
if (sentryCLIMatch) {
// Sentry already added to lane. Update it.
// sentryCLIMatch[1] contains the leading newline and whitespace
return (
content.slice(0, sentryCLIMatch.index + lane.index) +
sentryCLIMatch[1] +
templates.getFastlaneSnippet(org, project).trim() +
content.slice(
sentryCLIMatch.index + sentryCLIMatch[0].length + lane.index,
Expand Down
2 changes: 1 addition & 1 deletion src/apple/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function getObjcSnippet(dsn: string, enableLogs: boolean): string {
}

export function getFastlaneSnippet(org: string, project: string): string {
return ` sentry_cli(
return ` sentry_debug_files_upload(
org_slug: '${org}',
project_slug: '${project}',
include_sources: true
Expand Down
16 changes: 8 additions & 8 deletions test/apple/fastfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ end
});

describe('#addSentryToLane', () => {
describe('sentry_cli is not present', () => {
describe('sentry_debug_files_upload is not present', () => {
it('should return original content', () => {
// -- Arrange --
const content = `
Expand All @@ -293,7 +293,7 @@ platform :ios do
lane :test do
puts 'Hello, world!'

sentry_cli(
sentry_debug_files_upload(
org_slug: 'test-org',
project_slug: 'test-project',
include_sources: true
Expand All @@ -304,19 +304,19 @@ end
});
});

describe('sentry_cli is present', () => {
describe('sentry_debug_files_upload is present', () => {
it('should return updated content', () => {
// -- Arrange --
const content = `
platform :ios do
lane :test do
puts 'Hello, world!'

sentry_cli(org_slug: 'test-org', project_slug: 'test-project')
sentry_debug_files_upload(org_slug: 'test-org', project_slug: 'test-project')
end
end
`;
const lane = { index: 34, length: 92, name: 'test' };
const lane = { index: 34, length: 108, name: 'test' };

// -- Act --
const result = exportForTesting.addSentryToLane(
Expand All @@ -333,7 +333,7 @@ platform :ios do
lane :test do
puts 'Hello, world!'

sentry_cli(
sentry_debug_files_upload(
org_slug: 'test-org',
project_slug: 'test-project',
include_sources: true
Expand Down Expand Up @@ -446,7 +446,7 @@ platform :ios do
lane :test do
puts 'Hello, world!'

sentry_cli(
sentry_debug_files_upload(
org_slug: 'test-org',
project_slug: 'test-project',
include_sources: true
Expand Down Expand Up @@ -518,7 +518,7 @@ end
lane :beta do
puts 'Beta lane'

sentry_cli(
sentry_debug_files_upload(
org_slug: 'test-org',
project_slug: 'test-project',
include_sources: true
Expand Down
2 changes: 1 addition & 1 deletion test/apple/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fi

// -- Assert --
expect(snippet).toBe(
` sentry_cli(
` sentry_debug_files_upload(
org_slug: 'test-org',
project_slug: 'test-project',
include_sources: true
Expand Down
Loading