Skip to content

Commit 5c091c6

Browse files
dooverscameroncooke
authored andcommitted
fix: include stdout diagnostics when stderr is empty on swift package failure
SPM writes compiler diagnostics to stdout, not stderr. The ?? operator does not treat empty string as falsy, so when stderr is "" the diagnostics in stdout were never included in the error response. Switching to || fixes the fallback for all three affected tools. Fixes #243
1 parent c342fa2 commit 5c091c6

6 files changed

Lines changed: 61 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
7+
- Fixed `swift_package_build`, `swift_package_test`, and `swift_package_clean` swallowing compiler diagnostics on failure by treating empty stderr as falsy, so stdout diagnostics are included in the error response ([#243](https://github.com/getsentry/XcodeBuildMCP/issues/243)).
8+
39
## [2.1.0]
410

511
### Added

src/mcp/tools/swift-package/__tests__/swift_package_build.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,32 @@ describe('swift_package_build plugin', () => {
228228
});
229229
});
230230

231+
it('should include stdout diagnostics when stderr is empty on build failure', async () => {
232+
const executor = createMockExecutor({
233+
success: false,
234+
error: '',
235+
output:
236+
"main.swift:10:25: error: cannot find type 'DOESNOTEXIST' in scope\nlet broken: DOESNOTEXIST = 42",
237+
});
238+
239+
const result = await swift_package_buildLogic(
240+
{
241+
packagePath: '/test/package',
242+
},
243+
executor,
244+
);
245+
246+
expect(result).toEqual({
247+
content: [
248+
{
249+
type: 'text',
250+
text: "Error: Swift package build failed\nDetails: main.swift:10:25: error: cannot find type 'DOESNOTEXIST' in scope\nlet broken: DOESNOTEXIST = 42",
251+
},
252+
],
253+
isError: true,
254+
});
255+
});
256+
231257
it('should handle spawn error', async () => {
232258
const executor = async () => {
233259
throw new Error('spawn ENOENT');

src/mcp/tools/swift-package/__tests__/swift_package_test.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,32 @@ describe('swift_package_test plugin', () => {
218218
});
219219
});
220220

221+
it('should include stdout diagnostics when stderr is empty on test failure', async () => {
222+
const mockExecutor = createMockExecutor({
223+
success: false,
224+
error: '',
225+
output:
226+
"main.swift:10:25: error: cannot find type 'DOESNOTEXIST' in scope\nlet broken: DOESNOTEXIST = 42",
227+
});
228+
229+
const result = await swift_package_testLogic(
230+
{
231+
packagePath: '/test/package',
232+
},
233+
mockExecutor,
234+
);
235+
236+
expect(result).toEqual({
237+
content: [
238+
{
239+
type: 'text',
240+
text: "Error: Swift package tests failed\nDetails: main.swift:10:25: error: cannot find type 'DOESNOTEXIST' in scope\nlet broken: DOESNOTEXIST = 42",
241+
},
242+
],
243+
isError: true,
244+
});
245+
});
246+
221247
it('should handle spawn error', async () => {
222248
const mockExecutor = async () => {
223249
throw new Error('spawn ENOENT');

src/mcp/tools/swift-package/swift_package_build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function swift_package_buildLogic(
5757
try {
5858
const result = await executor(['swift', ...swiftArgs], 'Swift Package Build', false, undefined);
5959
if (!result.success) {
60-
const errorMessage = result.error ?? result.output ?? 'Unknown error';
60+
const errorMessage = result.error || result.output || 'Unknown error';
6161
return createErrorResponse('Swift package build failed', errorMessage);
6262
}
6363

src/mcp/tools/swift-package/swift_package_clean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function swift_package_cleanLogic(
2626
try {
2727
const result = await executor(['swift', ...swiftArgs], 'Swift Package Clean', false, undefined);
2828
if (!result.success) {
29-
const errorMessage = result.error ?? result.output ?? 'Unknown error';
29+
const errorMessage = result.error || result.output || 'Unknown error';
3030
return createErrorResponse('Swift package clean failed', errorMessage);
3131
}
3232

src/mcp/tools/swift-package/swift_package_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function swift_package_testLogic(
6767
try {
6868
const result = await executor(['swift', ...swiftArgs], 'Swift Package Test', false, undefined);
6969
if (!result.success) {
70-
const errorMessage = result.error ?? result.output ?? 'Unknown error';
70+
const errorMessage = result.error || result.output || 'Unknown error';
7171
return createErrorResponse('Swift package tests failed', errorMessage);
7272
}
7373

0 commit comments

Comments
 (0)