Skip to content

Commit

Permalink
Merge pull request #2498 from evidence-dev/fix/2496-better-error-mess…
Browse files Browse the repository at this point in the history
…age-when-running-sources-without-a-sources-directory

Better error message when running sources without a sources directory
  • Loading branch information
zachstence committed Sep 13, 2024
2 parents c8c13e3 + 9efe214 commit 72863b3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-oranges-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/sdk': patch
---

Dont throw error if sources directory doesn't exist when running sources
Empty file removed e2e/basic/sources/.gitkeep
Empty file.
Empty file removed e2e/spa/sources/.gitkeep
Empty file.
6 changes: 4 additions & 2 deletions packages/lib/sdk/src/plugins/datasources/evalSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ export const evalSources = async (dataPath, metaPath, filters, strict) => {
// Setup work
const [sourcePlugins, sources] = await Promise.all([
loadSourcePlugins(),
loadSources(),
loadSources(pluginLoader),
loadCache(metaPath)
]).catch((e) => {
pluginLoader.fail();
throw e;
});

pluginLoader.succeed();
if (sources.length) {
pluginLoader.succeed();
}

/** @type {import('./types.js').Manifest} */
const outputManifest = { renderedFiles: {}, locatedFiles: {}, locatedSchemas: [] };
Expand Down
18 changes: 14 additions & 4 deletions packages/lib/sdk/src/plugins/datasources/loadSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ const loadSource = async (sourcePath) => {
};

/**
* @param {import('ora').Ora} [spinner]
* @returns {Promise<Array<import('./schemas/datasource.schema.js').DatasourceSpecFile & {dir: string}>>}
*/
export const loadSources = async () => {
const sourceDirs = await fs
.readdir(sourcesDirectory)
.then((dirs) => dirs.map((dir) => path.join(sourcesDirectory, dir)));
export const loadSources = async (spinner) => {
/** @type {string[]} */
let sourceDirs = [];
try {
sourceDirs = await fs
.readdir(sourcesDirectory)
.then((dirs) => dirs.map((dir) => path.join(sourcesDirectory, dir)));
} catch (e) {
spinner?.stopAndPersist({
symbol: '⚠',
text: chalk.yellow('No sources directory found, no sources to run')
});
}

return /** @type {Array<import('./schemas/datasource.schema.js').DatasourceSpecFile & {dir: string}>}*/ (
await Promise.all(
Expand Down

0 comments on commit 72863b3

Please sign in to comment.