GeezerVison is showing github.com — improve error handling and logging for GitHub API failures in upgrade… · markathomas/opencode@d6eff3b
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/opencode/src/installation
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: install +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,7 +48,7 @@ if [ -z "$requested_version" ]; then |
48 | 48 | url="https://github.com/sst/opencode/releases/latest/download/$filename" |
49 | 49 | specific_version=$(curl -s https://api.github.com/repos/sst/opencode/releases/latest | awk -F'"' '/"tag_name": "/ {gsub(/^v/, "", $4); print $4}') |
50 | 50 |
|
51 | | - if [[ $? -ne 0 ]]; then |
| 51 | + if [[ $? -ne 0 || -z "$specific_version" ]]; then |
52 | 52 | echo "${RED}Failed to fetch version information${NC}" |
53 | 53 | exit 1 |
54 | 54 | fi |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/opencode/src/installation/index.ts +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -140,6 +140,12 @@ export namespace Installation { |
140 | 140 | export async function latest() { |
141 | 141 | return fetch("https://api.github.com/repos/sst/opencode/releases/latest") |
142 | 142 | .then((res) => res.json()) |
143 | | - .then((data) => data.tag_name.slice(1) as string) |
| 143 | + .then((data) => { |
| 144 | + if (typeof data.tag_name !== "string") { |
| 145 | + log.error("GitHub API error", data) |
| 146 | + throw new Error("failed to fetch latest version") |
| 147 | + } |
| 148 | + return data.tag_name.slice(1) as string |
| 149 | + }) |
144 | 150 | } |
145 | 151 | } |