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

fix: Clarify error message when non-magical part of input glob does not exist #21

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/garment/__tests__/garment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,21 @@ describe('createFileInput', () => {

expect(filesCount).toBe(2);
});

test('should throw with a clear error message when rootDir does not exist', async () => {
const testDir = await initFixture('basic');

const nonExistingDirectory = Path.join(testDir, 'nonExistingDirectory');
const generator = createFileInput({
rootDir: nonExistingDirectory
});

const createFileInputForNonExistingRootDirectory = () => {
generator.next();
};

expect(createFileInputForNonExistingRootDirectory).toThrow(
/nonExistingDirectory/
);
});
});
5 changes: 5 additions & 0 deletions core/garment/src/garment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,11 @@ export function* createFileInput(
{ rootDir, files = [], include, exclude = [] }: Input,
fsInstance = fs
) {
if (!fsInstance.existsSync(rootDir)) {
throw new Error(`The path ${rootDir} does not exist, please check the input property
of your tasks in your garment.json file and verify that the "non-magical" part of your glob
is a path to an already existing directory`);
}
const filesFromGlob = include
? globby.sync(include, {
cwd: rootDir,
Expand Down
2 changes: 1 addition & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Defines which files are sent as an input to the runner. If defined as an object,
}
```

`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.
`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.

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;

Expand Down