Skip to content

Commit

Permalink
Merge pull request #282 from davidtheclark/add-filepath-to-loader-errors
Browse files Browse the repository at this point in the history
add filepath to loader errors
  • Loading branch information
d-fischer authored Nov 21, 2022
2 parents ec975e4 + 706c2ee commit 68298d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

- **Breaking change:** Drop support for Node 10.
- **Breaking change:** Use npm package [js-yaml](https://www.npmjs.com/package/js-yaml) to parse YAML instead of npm package [yaml](https://www.npmjs.com/package/yaml).
- Added: Loader errors now include the path of the file that was tried to be loaded.

## 7.1.0

- Added: additional default `searchPlaces` within a .config subdirectory (without leading dot in the file name)
- Added: Additional default `searchPlaces` within a .config subdirectory (without leading dot in the file name)

## 7.0.1

Expand Down
12 changes: 8 additions & 4 deletions src/Explorer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { ExplorerBase } from './ExplorerBase';
import { readFile } from './readFile';
import { cacheWrapper } from './cacheWrapper';
import { ExplorerBase } from './ExplorerBase';
import { getDirectory } from './getDirectory';
import { readFile } from './readFile';
import { CosmiconfigResult, ExplorerOptions, LoadedFileContent } from './types';

class Explorer extends ExplorerBase<ExplorerOptions> {
Expand Down Expand Up @@ -78,8 +78,12 @@ class Explorer extends ExplorerBase<ExplorerOptions> {
return undefined;
}
const loader = this.getLoaderEntryForFile(filepath);
const loaderResult = await loader(filepath, content);
return loaderResult;
try {
return await loader(filepath, content);
} catch (e) {
e.filepath = filepath;
throw e;
}
}

private async createCosmiconfigResult(
Expand Down
13 changes: 8 additions & 5 deletions src/ExplorerSync.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { ExplorerBase } from './ExplorerBase';
import { readFileSync } from './readFile';
import { cacheWrapperSync } from './cacheWrapper';
import { ExplorerBase } from './ExplorerBase';
import { getDirectorySync } from './getDirectory';
import { readFileSync } from './readFile';
import {
CosmiconfigResult,
ExplorerOptionsSync,
Expand Down Expand Up @@ -77,9 +77,12 @@ class ExplorerSync extends ExplorerBase<ExplorerOptionsSync> {
return undefined;
}
const loader = this.getLoaderEntryForFile(filepath);
const loaderResult = loader(filepath, content);

return loaderResult;
try {
return loader(filepath, content);
} catch (e) {
e.filepath = filepath;
throw e;
}
}

private createCosmiconfigResultSync(
Expand Down

0 comments on commit 68298d4

Please sign in to comment.