Skip to content

Commit

Permalink
fix: add deploy errors to validate error message (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel authored Mar 11, 2024
1 parent 4a46268 commit d60804b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/commands/project/deploy/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
this.logSuccess(messages.getMessage('info.SuccessfulValidation', [deploy.id]));
this.log(messages.getMessage('info.suggestedQuickDeploy', [this.config.bin, deploy.id]));
} else {
let componentDeployErrors = result.response.errorMessage;
if (!result.response.errorMessage) {
componentDeployErrors = '';
// gather component deployment errors
const failures = formatter.getFileResponseFailures();
failures?.map((f) => {
componentDeployErrors += `${f.problemType} in ${f.fullName} - ${f.error}${os.EOL}`;
});
}
throw messages
.createError('error.FailedValidation', [
deploy.id,
Expand All @@ -233,7 +242,7 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
(warning: CodeCoverageWarnings & { name?: string }) =>
`${warning.name ? `${warning.name} - ` : ''}${warning.message}`
),
result.response.errorMessage,
componentDeployErrors,
result.response.numberComponentErrors ? `${result.response.numberComponentErrors} component error(s)` : '',
]
.join(os.EOL)
Expand Down
49 changes: 30 additions & 19 deletions src/formatters/deployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import * as path from 'node:path';
import { EOL } from 'node:os';
import * as fs from 'node:fs';
import { ux } from '@oclif/core';
import { ComponentStatus, DeployResult, FileResponse, RequestStatus } from '@salesforce/source-deploy-retrieve';
import {
ComponentStatus,
DeployResult,
FileResponse,
FileResponseFailure,
RequestStatus,
} from '@salesforce/source-deploy-retrieve';
import { Org, SfError, Lifecycle } from '@salesforce/core';
import { Duration, ensureArray, sortBy } from '@salesforce/kit';
import {
Expand Down Expand Up @@ -131,6 +137,27 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
return 'normal';
}

public getFileResponseFailures(): FileResponseFailure[] | undefined {
const failures = this.relativeFiles.filter(isSdrFailure);
const deployMessages = ensureArray(this.result.response.details?.componentFailures);
if (deployMessages.length > failures.length) {
const failureKeySet = new Set(failures.map((f) => makeKey(f.type, f.fullName)));
// if there's additional failures in the API response, find the failure and add it to the output
deployMessages
.filter((m) => !m.componentType || !failureKeySet.has(makeKey(m.componentType, m.fullName)))
.map((deployMessage) => {
failures.push({
fullName: deployMessage.fullName,
type: deployMessage.componentType ?? 'UNKNOWN',
state: ComponentStatus.Failed,
error: deployMessage.problem ?? 'UNKNOWN',
problemType: deployMessage.problemType ?? 'Error',
});
});
}
return failures;
}

private maybeCreateRequestedReports(): void {
// only generate reports if test results are presented
if (this.coverageOptions.reportFormats?.length) {
Expand Down Expand Up @@ -269,24 +296,8 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
private displayFailures(): void {
if (this.result.response.status === RequestStatus.Succeeded) return;

const failures = this.relativeFiles.filter(isSdrFailure);
const deployMessages = ensureArray(this.result.response.details?.componentFailures);
if (deployMessages.length > failures.length) {
const failureKeySet = new Set(failures.map((f) => makeKey(f.type, f.fullName)));
// if there's additional failures in the API response, find the failure and add it to the output
deployMessages
.filter((m) => !m.componentType || !failureKeySet.has(makeKey(m.componentType, m.fullName)))
.map((deployMessage) => {
failures.push({
fullName: deployMessage.fullName,
type: deployMessage.componentType ?? 'UNKNOWN',
state: ComponentStatus.Failed,
error: deployMessage.problem ?? 'UNKNOWN',
problemType: deployMessage.problemType ?? 'Error',
});
});
}
if (!failures.length) return;
const failures = this.getFileResponseFailures();
if (!failures?.length) return;

const columns = {
problemType: { header: 'Type' },
Expand Down

0 comments on commit d60804b

Please sign in to comment.