Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Fix Bug 650: Remove reading warnings, add additional error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
azlam-abdulsalam committed Aug 11, 2021
1 parent a57e65f commit 514abf4
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions packages/core/src/sfpcommands/source/DeploySourceToOrgImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PackageManifest from "../../package/PackageManifest";
import DeployErrorDisplayer from "../../display/DeployErrorDisplayer";
import * as fs from "fs-extra";
import DeploymentExecutor, { DeploySourceResult } from "./DeploymentExecutor";
const Table = require("cli-table");

export default class DeploySourceToOrgImpl implements DeploymentExecutor {
private mdapiDir: string;
Expand Down Expand Up @@ -103,16 +104,16 @@ export default class DeploySourceToOrgImpl implements DeploymentExecutor {
);
} catch (err) {
if (this.deployment_options["checkonly"])
SFPLogger.log(`Validation Failed`, null, this.packageLogger);
else SFPLogger.log(`Deployment Failed`, null, this.packageLogger);
SFPLogger.log(`Validation Failed`, LoggerLevel.ERROR, this.packageLogger);
else SFPLogger.log(`Deployment Failed`, LoggerLevel.ERROR, this.packageLogger);
break;
}

let resultAsJSON = JSON.parse(result);
if (resultAsJSON["status"] == 1) {
SFPLogger.log(
"Validation/Deployment Failed",
null,
"Deployment Failed",
LoggerLevel.ERROR,
this.packageLogger
);
commandExecStatus = false;
Expand Down Expand Up @@ -155,7 +156,7 @@ export default class DeploySourceToOrgImpl implements DeploymentExecutor {
let filepath=`sfpowerscripts/mdapiDeployReports`;
fs.mkdirpSync(filepath);
let child = child_process.exec(
`sfdx force:mdapi:deploy:report --json -i ${deploy_id} -u ${this.target_org}`,
`sfdx force:mdapi:deploy:report --json -i ${deploy_id} -u ${this.target_org} -w 30`,
{
cwd: this.project_directory,
encoding: "utf8",
Expand All @@ -168,29 +169,47 @@ export default class DeploySourceToOrgImpl implements DeploymentExecutor {
});


child.stderr.on("data", (data) => {
reportAsJSON += data.toString();
});

await onExit(child);

return "Succesfully Deployed";
} catch (err) {
let report = JSON.parse(reportAsJSON);
let report=JSON.parse(reportAsJSON);

if(report.result.details.componentFailures && report.result.details.componentFailures.length>0)
{
DeployErrorDisplayer.printMetadataFailedToDeploy(
report.result.details.componentFailures,this.packageLogger
);
return report.message;
}
else if(report.result.details.runTestResult?.codeCoverageWarnings)
{
this.displayCodeCoverageWarnings(report.result.details.runTestResult.codeCoverageWarnings);
return "Unable to deploy due to unsatisfactory code coverage";
}
else
{
return "Unable to fetch report";
}
}
}

private displayCodeCoverageWarnings(coverageWarnings: any) {
let table = new Table({
head: ["Name", "Message"],
});
if (Array.isArray(coverageWarnings)) {
coverageWarnings.forEach(element => {
table.push([element.name, element.message]);
});
}
else {
table.push([coverageWarnings.name, coverageWarnings.message]);
}
SFPLogger.log("Unable to deploy due to unsatisfactory code coverage, Check the following classses:", LoggerLevel.WARN, this.packageLogger);
SFPLogger.log(table.toString(), LoggerLevel.WARN, this.packageLogger);
}

private buildExecCommand(): string {
let apexclasses;

Expand Down

0 comments on commit 514abf4

Please sign in to comment.