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
8 changes: 4 additions & 4 deletions packages/cli/src/utils/socket/api.mts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export async function queryApiSafeText(
return {
ok: false,
message,
cause: networkDiagnostics,
cause: `${networkDiagnostics} (path: ${path})`,
}
}

Expand Down Expand Up @@ -497,7 +497,7 @@ export async function queryApiSafeText(
return {
ok: false,
message: 'API request failed',
cause: 'Unexpected error reading response text',
cause: `Unexpected error reading response text (path: ${path})`,
}
}
}
Expand Down Expand Up @@ -634,7 +634,7 @@ export async function sendApiRequest<T>(
return {
ok: false,
message,
cause: networkDiagnostics,
cause: `${networkDiagnostics} (path: ${path})`,
}
}

Expand Down Expand Up @@ -677,7 +677,7 @@ export async function sendApiRequest<T>(
return {
ok: false,
message: 'API request failed',
cause: 'Unexpected error parsing response JSON',
cause: `Unexpected error parsing response JSON (path: ${path})`,
}
}
}
7 changes: 7 additions & 0 deletions packages/cli/test/unit/utils/socket/api.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ describe('api utilities', () => {
expect(result.ok).toBe(false)
if (!result.ok) {
expect(result.message).toContain('failed')
// The cause must include the request path so the user can tell
// which endpoint failed when several calls are in flight.
expect(result.cause).toContain('(path: test/path)')
}
expect(mockFailAndStop).toHaveBeenCalled()
})
Expand All @@ -490,6 +493,7 @@ describe('api utilities', () => {
expect(result.ok).toBe(false)
if (!result.ok) {
expect(result.cause).toContain('response text')
expect(result.cause).toContain('(path: test/path)')
}
})
})
Expand Down Expand Up @@ -625,6 +629,8 @@ describe('api utilities', () => {
expect(result.ok).toBe(false)
if (!result.ok) {
expect(result.message).toContain('failed')
// Request path must be surfaced in error cause for debuggability.
expect(result.cause).toContain('(path: test/path)')
}
})

Expand All @@ -639,6 +645,7 @@ describe('api utilities', () => {
expect(result.ok).toBe(false)
if (!result.ok) {
expect(result.cause).toContain('parsing')
expect(result.cause).toContain('(path: test/path)')
}
})

Expand Down