Skip to content

Commit 62e9cfa

Browse files
committed
fix: no ENOENT when nothing retrieved to specific directory
1 parent a2766a2 commit 62e9cfa

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/commands/project/retrieve/start.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
354354
);
355355
return directories;
356356
}
357+
// If we retrieved only a package.xml, just return.
358+
if (this.retrieveResult.getFileResponses().length < 2) {
359+
return;
360+
}
361+
357362
// getFileResponses fails once the files have been moved, calculate where they're moved to, and then move them
358363
this.retrieveResult.getFileResponses().forEach((fileResponse) => {
359364
fileResponse.filePath = fileResponse.filePath?.replace(join('main', 'default'), '');

test/nuts/retrieve/metadata.nut.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ describe('retrieve metadata NUTs', () => {
8383
await testkit.expect.filesToBeRetrieved(['myOutput/classes/*', 'myOutput/aura/**/*']);
8484
});
8585

86+
it('should warn when nothing retrieved into output-dir and not throw ENOENT', async () => {
87+
const result = await testkit.retrieve({ args: '--metadata ApexClass:NonExistant --output-dir myOutput' });
88+
expect(result?.status).to.equal(0);
89+
const retrieveResult = result?.result as unknown as RetrieveResultJson;
90+
expect(retrieveResult.success).to.equal(true);
91+
expect(retrieveResult.fileProperties).to.be.an('array').with.lengthOf(1);
92+
expect(retrieveResult.messages).to.deep.equal([
93+
{
94+
fileName: 'unpackaged/package.xml',
95+
problem: "Entity of type 'ApexClass' named 'NonExistant' cannot be found",
96+
},
97+
]);
98+
});
99+
86100
it('should retrieve ApexClasses from wildcard match', async () => {
87101
const response = await testkit.retrieve({ args: '--metadata "ApexClass:Test*"' });
88102
expect(response?.status).to.equal(0);

0 commit comments

Comments
 (0)