Emit more specific errors from backupVerifier

GitOrigin-RevId: 99475608f096be3e35fbaaf1825b99d145ea86f3
This commit is contained in:
Andrew Rumble 2025-03-06 16:06:04 +00:00 committed by Copybot
parent 36056e75d7
commit 061d67ee4b
2 changed files with 20 additions and 11 deletions

View file

@ -80,17 +80,23 @@ export async function verifyBlobs(historyId, hashes, projectCache) {
})
} catch (err) {
if (err instanceof NotFoundError) {
throw new BackupCorruptedError('missing blob', { path, hash })
throw new BackupCorruptedMissingBlobError('missing blob', {
path,
hash,
})
}
throw err
}
const backupHash = await blobHash.fromStream(blob.getByteLength(), stream)
if (backupHash !== hash) {
throw new BackupCorruptedError('hash mismatch for backed up blob', {
path,
hash,
backupHash,
})
throw new BackupCorruptedInvalidBlobError(
'hash mismatch for backed up blob',
{
path,
hash,
backupHash,
}
)
}
}
}
@ -173,7 +179,7 @@ export async function verifyProject(historyId, endTimestamp) {
)
} catch (err) {
if (err instanceof Chunk.NotPersistedError) {
throw new BackupRPOViolationError(
throw new BackupRPOViolationChunkNotBackedUpError(
'BackupRPOviolation: chunk not backed up',
chunk
)
@ -236,3 +242,6 @@ export async function healthCheck() {
await verifyBlob(historyId, hash)
}
}
export class BackupCorruptedMissingBlobError extends BackupCorruptedError {}
export class BackupCorruptedInvalidBlobError extends BackupCorruptedError {}
export class BackupRPOViolationChunkNotBackedUpError extends OError {}

View file

@ -247,9 +247,7 @@ describe('backupVerifier', function () {
})
it('should emit an error message referring to a missing chunk', async function () {
const stderr = response.stderr
expect(stderr).to.include('NotFoundError: no such file')
expect(stderr).to.include("bucketName: 'overleaf-test-history-chunks'")
expect(stderr).to.include("key: '340/000/000000000000000000/000000000'")
expect(stderr).to.include('BackupRPOViolationChunkNotBackedUpError')
})
})
describe('when a project blob is not backed up', function () {
@ -268,7 +266,9 @@ describe('backupVerifier', function () {
})
it('includes a BackupCorruptedError in stderr', function () {
expect(response.stderr).to.include('BackupCorruptedError: missing blob')
expect(response.stderr).to.include(
'BackupCorruptedMissingBlobError: missing blob'
)
})
})
})