Skip to content

Commit

Permalink
Async/await-ify upgradeFromTSAsync and upgradeFromPythonAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Nov 10, 2023
1 parent 012ffc7 commit 508e8b1
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions webapp/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ function upgradeFromBlocksAsync(): Promise<UpgradeResult> {
});
}

function upgradeFromTSAsync(): Promise<UpgradeResult> {
async function upgradeFromTSAsync(): Promise<UpgradeResult> {
const mainPkg = pkg.mainPkg;
const project = pkg.getEditorPkg(mainPkg);
const targetVersion = project.header.targetVersion;
Expand All @@ -942,23 +942,22 @@ function upgradeFromTSAsync(): Promise<UpgradeResult> {

pxt.debug("Applying upgrades to TypeScript")

return checkPatchAsync(patchedFiles)
.then(() => {
return {
success: true,
editor: pxt.JAVASCRIPT_PROJECT_NAME,
patchedFiles
};
})
.catch(e => {
return {
success: false,
errorCodes: e.errorCodes
};
});
try {
await checkPatchAsync(patchedFiles)
return {
success: true,
editor: pxt.JAVASCRIPT_PROJECT_NAME,
patchedFiles
};
} catch (e) {
return {
success: false,
errorCodes: e.errorCodes
};
};
}

function upgradeFromPythonAsync(): Promise<UpgradeResult> {
async function upgradeFromPythonAsync(): Promise<UpgradeResult> {
const mainPkg = pkg.mainPkg;
const project = pkg.getEditorPkg(mainPkg);
const targetVersion = project.header.targetVersion;
Expand All @@ -973,20 +972,19 @@ function upgradeFromPythonAsync(): Promise<UpgradeResult> {

pxt.debug("Applying upgrades to Python")

return checkPatchAsync(patchedFiles)
.then(() => {
return {
success: true,
editor: pxt.PYTHON_PROJECT_NAME,
patchedFiles
};
})
.catch(e => {
return {
success: false,
errorCodes: e.errorCodes
};
});
try {
await checkPatchAsync(patchedFiles);
return {
success: true,
editor: pxt.PYTHON_PROJECT_NAME,
patchedFiles
};
} catch (e) {
return {
success: false,
errorCodes: e.errorCodes
};
}
}

interface UpgradeError extends Error {
Expand Down

0 comments on commit 508e8b1

Please sign in to comment.