fix: Better git error handling (#509)

This commit is contained in:
Brace Sproul 2025-07-23 16:43:33 -07:00 • committed by GitHub
parent 6ac4deacd6
commit ec0c93ef94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 4 deletions

View file

@ -275,6 +275,16 @@ export async function initializeSandbox(
"error",
"Failed to clone repository. Please check your repo URL and permissions.",
);
const errorFields = {
...(cloneRepoRes instanceof Error
? {
name: cloneRepoRes.name,
message: cloneRepoRes.message,
stack: cloneRepoRes.stack,
}
: cloneRepoRes),
};
logger.error("Cloning repository failed", errorFields);
throw new Error("Failed to clone repository.");
}
const newBranchName =

View file

@ -5,6 +5,7 @@ import { TIMEOUT_SEC } from "@open-swe/shared/constants";
import { getSandboxErrorFields } from "../sandbox-error-fields.js";
import { getRepoAbsolutePath } from "@open-swe/shared/git";
import { ExecuteResponse } from "@daytonaio/sdk/src/types/ExecuteResponse.js";
import { withRetry } from "../retry.js";
const logger = createLogger(LogLevel.INFO, "GitHub-Git");
@ -102,12 +103,32 @@ export async function checkoutBranchAndCommit(
await sandbox.git.commit(absoluteRepoDir, "Apply patch", userName, userEmail);
// Push the changes using the git API so it handles authentication for us.
await sandbox.git.push(
absoluteRepoDir,
"git",
options.githubInstallationToken,
const pushRes = await withRetry(
async () => {
return await sandbox.git.push(
absoluteRepoDir,
"git",
options.githubInstallationToken,
);
},
{ retries: 3, delay: 0 },
);
if (pushRes instanceof Error) {
const errorFields = {
...(pushRes instanceof Error
? {
name: pushRes.name,
message: pushRes.message,
stack: pushRes.stack,
cause: pushRes.cause,
}
: pushRes),
};
logger.error("Failed to push changes", errorFields);
throw new Error("Failed to push changes");
}
logger.info("Successfully checked out & committed changes.", {
commitAuthor: userName,
});