Skip to content

Commit f754759

Browse files
committed
fix(github): guard new tools against non-2xx GitHub responses
list_tags, get_readme, get_latest_release, and create_pr_review (v1 + v2) now check response.ok before parsing the payload as success data, returning success:false with a real error message instead of crashing on .map() or silently returning undefined fields when GitHub returns a 404/422/etc.
1 parent b321202 commit f754759

4 files changed

Lines changed: 125 additions & 0 deletions

File tree

apps/sim/tools/github/create_pr_review.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ export const createPRReviewTool: ToolConfig<CreatePRReviewParams, PRReviewRespon
7474
},
7575

7676
transformResponse: async (response) => {
77+
if (!response.ok) {
78+
const error = await response.json().catch(() => ({}))
79+
return {
80+
success: false,
81+
error: error.message || `Failed to submit PR review (HTTP ${response.status})`,
82+
output: {
83+
content: '',
84+
metadata: { id: 0, state: '', body: '', html_url: '', commit_id: '' },
85+
},
86+
}
87+
}
88+
7789
const review = await response.json()
7890

7991
const content = `Review submitted for PR #${review.pull_request_url?.split('/').pop() ?? ''}
@@ -123,6 +135,24 @@ export const createPRReviewV2Tool: ToolConfig<CreatePRReviewParams, any> = {
123135
request: createPRReviewTool.request,
124136

125137
transformResponse: async (response: Response) => {
138+
if (!response.ok) {
139+
const error = await response.json().catch(() => ({}))
140+
return {
141+
success: false,
142+
error: error.message || `Failed to submit PR review (HTTP ${response.status})`,
143+
output: {
144+
id: 0,
145+
user: null,
146+
body: null,
147+
state: '',
148+
html_url: '',
149+
pull_request_url: '',
150+
commit_id: '',
151+
submitted_at: null,
152+
},
153+
}
154+
}
155+
126156
const review = await response.json()
127157
return {
128158
success: true,

apps/sim/tools/github/get_latest_release.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@ export const getLatestReleaseTool: ToolConfig<GetLatestReleaseParams, ReleaseRes
4545
},
4646

4747
transformResponse: async (response) => {
48+
if (!response.ok) {
49+
const error = await response.json().catch(() => ({}))
50+
return {
51+
success: false,
52+
error: error.message || `Failed to get latest release (HTTP ${response.status})`,
53+
output: {
54+
content: '',
55+
metadata: {
56+
id: 0,
57+
tag_name: '',
58+
name: '',
59+
html_url: '',
60+
tarball_url: '',
61+
zipball_url: '',
62+
draft: false,
63+
prerelease: false,
64+
created_at: '',
65+
published_at: '',
66+
},
67+
},
68+
}
69+
}
70+
4871
const data = await response.json()
4972

5073
const assetsInfo =
@@ -116,6 +139,30 @@ export const getLatestReleaseV2Tool: ToolConfig<GetLatestReleaseParams, any> = {
116139
request: getLatestReleaseTool.request,
117140

118141
transformResponse: async (response: Response) => {
142+
if (!response.ok) {
143+
const error = await response.json().catch(() => ({}))
144+
return {
145+
success: false,
146+
error: error.message || `Failed to get latest release (HTTP ${response.status})`,
147+
output: {
148+
id: 0,
149+
tag_name: '',
150+
name: '',
151+
body: null,
152+
html_url: '',
153+
tarball_url: '',
154+
zipball_url: '',
155+
draft: false,
156+
prerelease: false,
157+
author: null,
158+
assets: [],
159+
created_at: '',
160+
published_at: null,
161+
target_commitish: '',
162+
},
163+
}
164+
}
165+
119166
const data = await response.json()
120167
return {
121168
success: true,

apps/sim/tools/github/get_readme.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ export const getReadmeTool: ToolConfig<GetReadmeParams, ReadmeResponse> = {
5050
},
5151

5252
transformResponse: async (response) => {
53+
if (!response.ok) {
54+
const error = await response.json().catch(() => ({}))
55+
return {
56+
success: false,
57+
error: error.message || `Failed to get README (HTTP ${response.status})`,
58+
output: {
59+
content: '',
60+
metadata: { name: '', path: '', sha: '', size: 0, html_url: '', download_url: '' },
61+
},
62+
}
63+
}
64+
5365
const data = await response.json()
5466

5567
let decodedContent = ''
@@ -109,6 +121,24 @@ export const getReadmeV2Tool: ToolConfig<GetReadmeParams, any> = {
109121
request: getReadmeTool.request,
110122

111123
transformResponse: async (response: Response) => {
124+
if (!response.ok) {
125+
const error = await response.json().catch(() => ({}))
126+
return {
127+
success: false,
128+
error: error.message || `Failed to get README (HTTP ${response.status})`,
129+
output: {
130+
name: '',
131+
path: '',
132+
sha: '',
133+
size: 0,
134+
encoding: '',
135+
html_url: '',
136+
download_url: null,
137+
content: '',
138+
},
139+
}
140+
}
141+
112142
const data = await response.json()
113143

114144
let decodedContent = ''

apps/sim/tools/github/list_tags.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ export const listTagsTool: ToolConfig<ListTagsParams, TagsListResponse> = {
6363
},
6464

6565
transformResponse: async (response) => {
66+
if (!response.ok) {
67+
const error = await response.json().catch(() => ({}))
68+
return {
69+
success: false,
70+
error: error.message || `Failed to list tags (HTTP ${response.status})`,
71+
output: { content: '', metadata: { total_count: 0, tags: [] } },
72+
}
73+
}
74+
6675
const tags = await response.json()
6776

6877
const tagsList = tags
@@ -126,6 +135,15 @@ export const listTagsV2Tool: ToolConfig<ListTagsParams, any> = {
126135
request: listTagsTool.request,
127136

128137
transformResponse: async (response: Response) => {
138+
if (!response.ok) {
139+
const error = await response.json().catch(() => ({}))
140+
return {
141+
success: false,
142+
error: error.message || `Failed to list tags (HTTP ${response.status})`,
143+
output: { items: [], count: 0 },
144+
}
145+
}
146+
129147
const tags = await response.json()
130148
return {
131149
success: true,

0 commit comments

Comments
 (0)