Skip to content

Commit c23489a

Browse files
committed
Fix getRuntimeData bug
1 parent 22bd2a0 commit c23489a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

transforms/helpers/runtime-data.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getTelemetryFor } from 'ember-codemods-telemetry-helpers';
22
import path from 'path';
33
import { z } from 'zod';
4+
import logger from './log-helper';
45

56
const RuntimeDataSchema = z.object({
67
type: z.string().optional(),
@@ -14,12 +15,19 @@ const RuntimeDataSchema = z.object({
1415
export type RuntimeData = z.infer<typeof RuntimeDataSchema>;
1516

1617
/**
17-
* TODO
18+
* Gets telemetry data for the file and parses it into a valid `RuntimeData`
19+
* object.
1820
*/
1921
export function getRuntimeData(filePath: string): RuntimeData {
20-
const rawTelemetry = getTelemetryFor(path.resolve(filePath));
22+
let rawTelemetry = getTelemetryFor(path.resolve(filePath));
2123
if (!rawTelemetry) {
22-
throw new RuntimeDataError('Could not find runtime data');
24+
// Do not re-throw. The most likely reason this happened was because
25+
// the user's app threw an error. We still want the codemod to work if so.
26+
logger.error({
27+
filePath,
28+
error: new RuntimeDataError('Could not find runtime data'),
29+
});
30+
rawTelemetry = {};
2331
}
2432

2533
const result = RuntimeDataSchema.safeParse(rawTelemetry);

0 commit comments

Comments
 (0)