Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle missing recordings.log entries #617

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tender-waves-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"replayio": patch
---

Gracefully handle missing recordings.log entries
10 changes: 10 additions & 0 deletions packages/shared/src/recording/getRecordings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,14 @@ describe("getRecordings", () => {
])
);
});

it("should gracefully handle missing recording log entries", () => {
mockReadFileSync.mockReturnValue(`
{"id":"fake","kind":"addMetadata","metadata":{"processGroupId":"fake"}}
{"id":"fake","kind":"writeFinished"}
`);

const recordings = getRecordings();
expect(recordings).toHaveLength(0);
});
});
90 changes: 75 additions & 15 deletions packages/shared/src/recording/getRecordings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { basename } from "path";
import { logger } from "../logger";
import { recordingLogPath } from "./config";
import { readRecordingLog } from "./readRecordingLog";
import { LocalRecording, RECORDING_LOG_KIND } from "./types";
import { LocalRecording, LogEntry, RECORDING_LOG_KIND } from "./types";

export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
const recordings: LocalRecording[] = [];
Expand All @@ -22,7 +22,10 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
case RECORDING_LOG_KIND.addMetadata: {
const { id, metadata = {} } = entry;
const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

Object.assign(recording.metadata, metadata);

Expand Down Expand Up @@ -58,7 +61,11 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
const { data, id } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

if (recording.crashData) {
recording.crashData.push(data);
} else {
Expand All @@ -70,7 +77,11 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
const { id } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.recordingStatus = "crashed";
break;
}
Expand Down Expand Up @@ -117,7 +128,10 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
);

const recording = idToRecording[recordingId];
assert(recording, `Recording with ID "${recordingId}" not found`);
if (!recording) {
logNotFoundWarning(recordingId, entry);
continue;
}

const sourceMap = recording.metadata.sourceMaps.find(
sourceMap => sourceMap.id === parentId
Expand All @@ -134,31 +148,47 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
const { id } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.processingStatus = "failed";
break;
}
case RECORDING_LOG_KIND.processingFinished: {
const { id } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.processingStatus = "processed";
break;
}
case RECORDING_LOG_KIND.processingStarted: {
const { id } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.processingStatus = "processing";
break;
}
case RECORDING_LOG_KIND.recordingUnusable: {
const { id, reason } = entry;
const recording = idToRecording[id];

assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.recordingStatus = "unusable";
recording.unusableReason = reason;
break;
Expand All @@ -179,7 +209,10 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
assert(targetMapURLHash, '"sourcemapAdded" entry must have a "targetMapURLHash"');

const recording = idToRecording[recordingId];
assert(recording, `Recording with ID "${recordingId}" not found`);
if (!recording) {
logNotFoundWarning(recordingId, entry);
continue;
}

recording.metadata.sourceMaps.push({
id,
Expand All @@ -196,31 +229,47 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
const { id } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.uploadStatus = "failed";
break;
}
case RECORDING_LOG_KIND.uploadFinished: {
const { id } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.uploadStatus = "uploaded";
break;
}
case RECORDING_LOG_KIND.uploadStarted: {
const { id } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.uploadStatus = "uploading";
break;
}
case RECORDING_LOG_KIND.writeFinished: {
const { id, timestamp } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.recordingStatus = "finished";

const startTimestamp = idToStartTimestamp[id];
Expand All @@ -233,7 +282,11 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
const { id, path, timestamp } = entry;

const recording = idToRecording[id];
assert(recording, `Recording with ID "${id}" not found`);
if (!recording) {
logNotFoundWarning(id, entry);
continue;
}

recording.path = path;
idToStartTimestamp[id] = timestamp;
break;
Expand Down Expand Up @@ -273,3 +326,10 @@ export function getRecordings(processGroupIdFilter?: string): LocalRecording[] {
.sort((a, b) => b.date.getTime() - a.date.getTime())
);
}

function logNotFoundWarning(recordingId: string, entry: LogEntry) {
logger.error("RecordingLog:RecordingNotFound", {
recordingId,
entry,
});
}