Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit 2b92c62

Browse files
authored
fix: Clarify error message when non-magical part of input glob does not exist (#21)
1 parent 4c57e30 commit 2b92c62

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

core/garment/__tests__/garment.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,21 @@ describe('createFileInput', () => {
6363

6464
expect(filesCount).toBe(2);
6565
});
66+
67+
test('should throw with a clear error message when rootDir does not exist', async () => {
68+
const testDir = await initFixture('basic');
69+
70+
const nonExistingDirectory = Path.join(testDir, 'nonExistingDirectory');
71+
const generator = createFileInput({
72+
rootDir: nonExistingDirectory
73+
});
74+
75+
const createFileInputForNonExistingRootDirectory = () => {
76+
generator.next();
77+
};
78+
79+
expect(createFileInputForNonExistingRootDirectory).toThrow(
80+
/nonExistingDirectory/
81+
);
82+
});
6683
});

core/garment/src/garment.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,11 @@ export function* createFileInput(
10831083
{ rootDir, files = [], include, exclude = [] }: Input,
10841084
fsInstance = fs
10851085
) {
1086+
if (!fsInstance.existsSync(rootDir)) {
1087+
throw new Error(`The path ${rootDir} does not exist, please check the input property
1088+
of your tasks in your garment.json file and verify that the "non-magical" part of your glob
1089+
is a path to an already existing directory`);
1090+
}
10861091
const filesFromGlob = include
10871092
? globby.sync(include, {
10881093
cwd: rootDir,

docs/Configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Defines which files are sent as an input to the runner. If defined as an object,
246246
}
247247
```
248248

249-
`rootDir: string` defines where the input files are. `include: string[]` and `exclude: string[]` define glob patterns to include to or exclude from files set. Note, that each runner can have a default `include` and `exclude` patterns, so the developer only needs to define a `rootDir`. If `input` is a `string` then it defines a `rootDir` and uses default values `[**/*]` for include and `[]` for exclude, or the ones defined by runner.
249+
`rootDir: string` defines where the input files are. `include: string[]` and `exclude: string[]` define glob patterns to include to or exclude from files set. Note, that each runner can have a default `include` and `exclude` patterns, so the developer only needs to define a `rootDir`. If `input` is a `string` then it defines a `rootDir` and uses default values `[**/*]` for include and `[]` for exclude, or the ones defined by runner. Note that `rootDir` must exist and that when using globs, the non-magical part (the part before the first glob character) must exist.
250250

251251
If not specified, the files from previous tasks will be passed as input files. If you want to receive both files from the disk and previous tasks, you should specify `pipe` option as `true` or glob pattern;
252252

0 commit comments

Comments
 (0)