Skip to content

Commit

Permalink
Add debug logging to IR migration (fern-api#1417)
Browse files Browse the repository at this point in the history
* Add debug logging to IR migration

* Log IR filepath
  • Loading branch information
zachkirsch authored Mar 20, 2023
1 parent 4cc8764 commit 6b26a5d
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -168,6 +168,7 @@ class IntermediateRepresentationMigratorImpl implements IntermediateRepresentati
if (!shouldMigrate(migration)) {
break;
}
context.logger.debug(`Migrating IR from ${migration.laterVersion} to ${migration.earlierVersion}`);
migrated = migration.migrateBackwards(migrated, {
taskContext: context,
targetGenerator,
Original file line number Diff line number Diff line change
@@ -137,7 +137,12 @@ async function startJob({

const formData = new FormData();

formData.append("file", await stringifyLargeObject(migratedIntermediateRepresentation));
const irAsString = await stringifyLargeObject(migratedIntermediateRepresentation, {
onWrite: (irFilepath) => {
context.logger.debug("Wrote IR to disk: " + irFilepath);
},
});
formData.append("file", irAsString);

const url = urlJoin(getFiddleOrigin(), `/api/remote-gen/jobs/${job.jobId}/start`);
try {
9 changes: 7 additions & 2 deletions packages/commons/fs-utils/src/stringifyLargeObject.ts
Original file line number Diff line number Diff line change
@@ -3,9 +3,14 @@ import tmp from "tmp-promise";
import { AbsoluteFilePath } from "./AbsoluteFilePath";
import { streamObjectToFile } from "./streamObjectToFile";

export async function stringifyLargeObject(obj: unknown, { pretty }: { pretty?: boolean } = {}): Promise<string> {
export async function stringifyLargeObject(
obj: unknown,
{ pretty, onWrite }: { pretty?: boolean; onWrite?: (filepath: AbsoluteFilePath) => void } = {}
): Promise<string> {
const tmpFile = await tmp.file();
await streamObjectToFile(AbsoluteFilePath.of(tmpFile.path), obj, { pretty });
const filepath = AbsoluteFilePath.of(tmpFile.path);
await streamObjectToFile(filepath, obj, { pretty });
onWrite?.(filepath);
const fileContents = await readFile(tmpFile.path);
return fileContents.toString();
}

0 comments on commit 6b26a5d

Please sign in to comment.