fix: improve API error handling and add ARM architecture detection#17
Merged
Conversation
Closes #12, Closes #14 - Add URL normalization in giteaFetch to handle trailing slashes and /api/v1 suffix - Add detailed 404 error messages with troubleshooting hints (fixes #12) - Add architecture detection in Dockerfile and entrypoint.sh (fixes #14) - Graceful error when opencode binary incompatible with ARM - Document x86_64-only Docker support in README
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the reliability and diagnosability of the Gitea/Forgejo integration by normalizing the configured server base URL (avoiding double /api/v1 and trailing slash issues) and adds clearer ARM/x86_64 architecture handling for the Docker-based installation path.
Changes:
- Add base URL normalization in all Gitea API tools and provide a more actionable 404 error message.
- Add runtime architecture checking in
entrypoint.shplus a build-time warning in theDockerfile. - Document x86_64-only Docker support in English and Chinese READMEs.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
entrypoint.sh |
Normalizes server URL inputs and adds runtime architecture compatibility checks. |
Dockerfile |
Emits a build-time warning when building on non-x86_64/amd64 architectures. |
README.md |
Documents x86_64-only Docker support and points ARM users to source install. |
README_zh.md |
Same as README.md (Chinese localization). |
.opencode-review/tools/gitea-pr-diff.ts |
Normalizes base URL and improves 404 troubleshooting for PR diff fetches. |
.opencode-review/tools/gitea-pr-files.ts |
Normalizes base URL and improves 404 troubleshooting for PR file listing. |
.opencode-review/tools/gitea-review.ts |
Normalizes base URL and improves 404 troubleshooting for review submission. |
.opencode-review/tools/gitea-comment.ts |
Normalizes base URL and improves 404 troubleshooting for commenting. |
.opencode-review/tools/gitea-incremental-diff.ts |
Normalizes base URL and improves 404 troubleshooting for incremental diff logic. |
Comment on lines
+23
to
24
| if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required") | ||
| if (!token) throw new Error("GITEA_TOKEN environment variable is required") |
Comment on lines
+20
to
25
| const rawUrl = process.env.GITEA_SERVER_URL || process.env.GITHUB_SERVER_URL | ||
| const token = process.env.GITEA_TOKEN || process.env.GITHUB_TOKEN | ||
|
|
||
| if (!baseUrl) throw new Error("GITEA_SERVER_URL environment variable is required") | ||
| if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required") | ||
| if (!token) throw new Error("GITEA_TOKEN environment variable is required") | ||
|
|
Comment on lines
+79
to
83
| # Normalize: remove trailing slashes and /api/v1 suffix | ||
| if [ -n "$GITEA_SERVER_URL" ]; then | ||
| export GITEA_SERVER_URL="${GITEA_SERVER_URL%/}" | ||
| export GITEA_SERVER_URL="${GITEA_SERVER_URL%/api/v1}" | ||
| return 0 |
Comment on lines
233
to
236
| case "$command" in | ||
| review) | ||
| check_architecture | ||
| setup_config |
Comment on lines
+28
to
+30
| function normalizeBaseUrl(url: string): string { | ||
| return url.replace(/\/+$/, "").replace(/\/api\/v1\/?$/, "") | ||
| } |
Comment on lines
+33
to
37
| const rawUrl = process.env.GITEA_SERVER_URL || process.env.GITHUB_SERVER_URL | ||
| const token = process.env.GITEA_TOKEN || process.env.GITHUB_TOKEN | ||
|
|
||
| if (!baseUrl) throw new Error("GITEA_SERVER_URL environment variable is required") | ||
| if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required") | ||
| if (!token) throw new Error("GITEA_TOKEN environment variable is required") |
| const token = process.env.GITEA_TOKEN || process.env.GITHUB_TOKEN | ||
|
|
||
| if (!baseUrl) throw new Error("GITEA_SERVER_URL environment variable is required") | ||
| if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required") |
Comment on lines
+52
to
57
| const rawUrl = process.env.GITEA_SERVER_URL || process.env.GITHUB_SERVER_URL | ||
| const token = process.env.GITEA_TOKEN || process.env.GITHUB_TOKEN | ||
|
|
||
| if (!baseUrl) throw new Error("GITEA_SERVER_URL environment variable is required") | ||
| if (!rawUrl) throw new Error("GITEA_SERVER_URL environment variable is required") | ||
| if (!token) throw new Error("GITEA_TOKEN environment variable is required") | ||
|
|
| }> | ||
| } | ||
|
|
||
| function normalizeBaseUrl(url: string): string { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
normalizeBaseUrl) to handle trailing slashes and/api/v1suffix inGITEA_SERVER_URL. Add detailed 404 error messages with troubleshooting hints to help users diagnose misconfiguration.opencode-aibinary only supports x86_64/amd64. Now the Dockerfile shows a build-time warning, and the entrypoint checks at runtime whether the binary actually works on non-x86 architectures, with a clear error message pointing users to the source installation method.Changes
gitea-pr-diff.tsnormalizeBaseUrl()+ improved 404 errorgitea-pr-files.tsnormalizeBaseUrl()+ improved 404 errorgitea-review.tsnormalizeBaseUrl()+ improved 404 errorgitea-comment.tsnormalizeBaseUrl()+ improved 404 errorgitea-incremental-diff.tsnormalizeBaseUrl()+ improved 404 errorentrypoint.shcheck_architecture()function; normalize URL ininfer_gitea_server_url()DockerfileREADME.md/README_zh.mdRoot Cause Analysis
Issue #12: The error URL
https://gitea-hosted.com/api/swaggerin the 404 response is Gitea's default error format — it's NOT generated by our code. The actual API request likely fails due toGITEA_SERVER_URLhaving trailing slashes (e.g.,https://host.com/→https://host.com//api/v1/...) or including/api/v1already.Issue #14:
opencode-aiships a pre-compiled binary (.opencode) that only supports x86_64. On ARM platforms, it fails with glibc symbol errors. This is an upstream limitation.