Skip to content

Commit d60804b

Browse files
authored
fix: add deploy errors to validate error message (#938)
1 parent 4a46268 commit d60804b

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

src/commands/project/deploy/validate.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
224224
this.logSuccess(messages.getMessage('info.SuccessfulValidation', [deploy.id]));
225225
this.log(messages.getMessage('info.suggestedQuickDeploy', [this.config.bin, deploy.id]));
226226
} else {
227+
let componentDeployErrors = result.response.errorMessage;
228+
if (!result.response.errorMessage) {
229+
componentDeployErrors = '';
230+
// gather component deployment errors
231+
const failures = formatter.getFileResponseFailures();
232+
failures?.map((f) => {
233+
componentDeployErrors += `${f.problemType} in ${f.fullName} - ${f.error}${os.EOL}`;
234+
});
235+
}
227236
throw messages
228237
.createError('error.FailedValidation', [
229238
deploy.id,
@@ -233,7 +242,7 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
233242
(warning: CodeCoverageWarnings & { name?: string }) =>
234243
`${warning.name ? `${warning.name} - ` : ''}${warning.message}`
235244
),
236-
result.response.errorMessage,
245+
componentDeployErrors,
237246
result.response.numberComponentErrors ? `${result.response.numberComponentErrors} component error(s)` : '',
238247
]
239248
.join(os.EOL)

src/formatters/deployResultFormatter.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import * as path from 'node:path';
88
import { EOL } from 'node:os';
99
import * as fs from 'node:fs';
1010
import { ux } from '@oclif/core';
11-
import { ComponentStatus, DeployResult, FileResponse, RequestStatus } from '@salesforce/source-deploy-retrieve';
11+
import {
12+
ComponentStatus,
13+
DeployResult,
14+
FileResponse,
15+
FileResponseFailure,
16+
RequestStatus,
17+
} from '@salesforce/source-deploy-retrieve';
1218
import { Org, SfError, Lifecycle } from '@salesforce/core';
1319
import { Duration, ensureArray, sortBy } from '@salesforce/kit';
1420
import {
@@ -131,6 +137,27 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
131137
return 'normal';
132138
}
133139

140+
public getFileResponseFailures(): FileResponseFailure[] | undefined {
141+
const failures = this.relativeFiles.filter(isSdrFailure);
142+
const deployMessages = ensureArray(this.result.response.details?.componentFailures);
143+
if (deployMessages.length > failures.length) {
144+
const failureKeySet = new Set(failures.map((f) => makeKey(f.type, f.fullName)));
145+
// if there's additional failures in the API response, find the failure and add it to the output
146+
deployMessages
147+
.filter((m) => !m.componentType || !failureKeySet.has(makeKey(m.componentType, m.fullName)))
148+
.map((deployMessage) => {
149+
failures.push({
150+
fullName: deployMessage.fullName,
151+
type: deployMessage.componentType ?? 'UNKNOWN',
152+
state: ComponentStatus.Failed,
153+
error: deployMessage.problem ?? 'UNKNOWN',
154+
problemType: deployMessage.problemType ?? 'Error',
155+
});
156+
});
157+
}
158+
return failures;
159+
}
160+
134161
private maybeCreateRequestedReports(): void {
135162
// only generate reports if test results are presented
136163
if (this.coverageOptions.reportFormats?.length) {
@@ -269,24 +296,8 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
269296
private displayFailures(): void {
270297
if (this.result.response.status === RequestStatus.Succeeded) return;
271298

272-
const failures = this.relativeFiles.filter(isSdrFailure);
273-
const deployMessages = ensureArray(this.result.response.details?.componentFailures);
274-
if (deployMessages.length > failures.length) {
275-
const failureKeySet = new Set(failures.map((f) => makeKey(f.type, f.fullName)));
276-
// if there's additional failures in the API response, find the failure and add it to the output
277-
deployMessages
278-
.filter((m) => !m.componentType || !failureKeySet.has(makeKey(m.componentType, m.fullName)))
279-
.map((deployMessage) => {
280-
failures.push({
281-
fullName: deployMessage.fullName,
282-
type: deployMessage.componentType ?? 'UNKNOWN',
283-
state: ComponentStatus.Failed,
284-
error: deployMessage.problem ?? 'UNKNOWN',
285-
problemType: deployMessage.problemType ?? 'Error',
286-
});
287-
});
288-
}
289-
if (!failures.length) return;
299+
const failures = this.getFileResponseFailures();
300+
if (!failures?.length) return;
290301

291302
const columns = {
292303
problemType: { header: 'Type' },

0 commit comments

Comments
 (0)