mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-10-19 14:17:20 +02:00
fix: preserve probe errors and complete refresh alerts
This commit is contained in:
1 parent
2b20abe0a5
commit
9a2707d4b8
6 files changed
+102
-11
No files matched your search
@@ -270,7 +270,10 @@ export default class AnonymizedFile {
|
||||
fetchFileInfoFromPath?: (filePath: string) => Promise<IFile | null>;
|
||||
};
|
||||
if (typeof source.fetchFileInfoFromPath !== "function") return null;
|
||||
const recovered = await source.fetchFileInfoFromPath(this.anonymizedPath);
|
||||
const recovered = await source.fetchFileInfoFromPath(this.anonymizedPath).catch(error => {
|
||||
void notifyOwnerAccessProblem(this.repository.owner.id, error);
|
||||
throw error;
|
||||
});
|
||||
if (!recovered) return null;
|
||||
recovered.repoId = this.repository.repoId;
|
||||
recovered.treeGeneration = this.repository.model.treeGeneration;
|
||||
|
||||
@@ -628,6 +628,14 @@ export default class Repository {
|
||||
|
||||
/** Update the repository if a new commit exists. */
|
||||
async updateIfNeeded(opt?: { force: boolean }): Promise<void> {
|
||||
try { await this.refreshIfNeeded(opt); }
|
||||
catch (error) {
|
||||
void notifyOwnerAccessProblem(this.owner.id, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private async refreshIfNeeded(opt?: { force: boolean }): Promise<void> {
|
||||
this.assertNotArchived();
|
||||
if (
|
||||
this._model.options.expirationMode !== "never" &&
|
||||
@@ -658,9 +666,6 @@ export default class Repository {
|
||||
repo: this.source.data.repoName,
|
||||
repositoryID: this.model.source.repositoryId,
|
||||
force: true,
|
||||
}).catch(error => {
|
||||
void notifyOwnerAccessProblem(this.owner.id, error);
|
||||
throw error;
|
||||
});
|
||||
|
||||
// update the repository name if it has changed. Persist it
|
||||
|
||||
@@ -52,7 +52,9 @@ export async function classifyGitHubMissError(
|
||||
repo: data.repoName,
|
||||
});
|
||||
return "commit_not_found";
|
||||
} catch {
|
||||
} catch (probeError) {
|
||||
if ((probeError as { status?: number; httpStatus?: number }).status !== 404 &&
|
||||
(probeError as { httpStatus?: number }).httpStatus !== 404) throw probeError;
|
||||
// Repo no longer exists at owner/repo. Try to recover via the cached
|
||||
// numeric GitHub id — if the repo was renamed, GET /repositories/{id}
|
||||
// resolves to its new full_name. See #409.
|
||||
@@ -87,7 +89,9 @@ export async function classifyGitHubMissError(
|
||||
return "repo_renamed";
|
||||
}
|
||||
return "repo_not_found";
|
||||
} catch {
|
||||
} catch (probeError) {
|
||||
if ((probeError as { status?: number; httpStatus?: number }).status !== 404 &&
|
||||
(probeError as { httpStatus?: number }).httpStatus !== 404) throw probeError;
|
||||
return "repo_not_found";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ export class GitHubRepository {
|
||||
try {
|
||||
await oct.repos.get({ owner: this.owner, repo: this.repo });
|
||||
repoExists = true;
|
||||
} catch {
|
||||
} catch (probeError) {
|
||||
if ((probeError as { status?: number }).status !== 404) throw probeError;
|
||||
repoExists = false;
|
||||
}
|
||||
throw new AnonymousError(
|
||||
|
||||
@@ -412,10 +412,13 @@ export default class GitHubStream extends GitHubBase {
|
||||
size: data.size,
|
||||
};
|
||||
} catch (error) {
|
||||
logger.debug("fetchFileInfoFromPath miss", {
|
||||
filePath,
|
||||
error: serializeError(error),
|
||||
});
|
||||
if ((error as { status?: number }).status !== 404) throw error;
|
||||
// A missing file and lost repository access both return 404. Only
|
||||
// report a normal miss after the repository probe remains readable.
|
||||
const code = await classifyGitHubMissError(error, this.data);
|
||||
if (code === "repo_not_found") {
|
||||
throw new AnonymousError(code, { httpStatus: 404, cause: error as Error });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user