Error handling, pagination support and cleanup#18
Conversation
- Wrap JSON.parse in try/catch for malformed API responses - Truncate error response bodies to prevent log leakage - Add 1MB response size limit to prevent memory exhaustion - Handle pagination for PRs with 100+ changed files
- Add 5-minute timeout on Z.ai API requests to prevent indefinite hangs
Z.ai Code ReviewThe changes improve robustness by adding pagination, timeouts, and memory limits. However, there is a specific logical fragility in the pagination implementation. 1. Pagination Logic Fragility (Bug Risk)In per_page: 100,
// ...
if (data.length < 100) break;If the Recommendation: Define const PER_PAGE = 100;
// ...
while (true) {
const { data } = await octokit.rest.pulls.listFiles({
// ...
per_page: PER_PAGE,
page,
});
files.push(...data);
if (data.length < PER_PAGE) break;
page++;
}2. Implicit Buffer ConversionIn Recommendation: Explicitly convert the chunk to a string for clarity and safety: data += chunk.toString('utf8');3. Memory Limit TimingThe check |
This pull request improves the robustness and reliability of the code that interacts with the Z.ai API and fetches pull request file changes. The main changes include adding pagination support for fetching changed files, introducing response size limits and request timeouts for API calls, and improving error handling for API responses.
API request and response handling improvements:
MAX_RESPONSE_SIZE) to prevent processing excessively large responses from the Z.ai API, and implemented logic to abort the request if this limit is exceeded.REQUEST_TIMEOUT_MS) for Z.ai API requests to avoid hanging indefinitely on slow or unresponsive calls.Pull request file fetching:
getChangedFilesfunction to support pagination, ensuring all changed files are fetched even when there are more than 100 files in a pull request.