Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when running sources without a sources directory #2498

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