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

fix(cli): handle missing target artifact dir #4112

Merged
merged 1 commit into from
Nov 25, 2019

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Nov 12, 2019

When creating a new artifact (e.g. Model or Repository) while the target directory does not exist yet (e.g. src/models or src/repositories), we used to abort CLI with a ENOENT error.

This commit is fixing our CLI to treat the missing directory as if it was empty and continue the operation if possible.

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@bajtos bajtos requested review from raymondfeng and a team November 12, 2019 14:52
@bajtos bajtos self-assigned this Nov 12, 2019
@bajtos bajtos added this to the Nov 2019 milestone milestone Nov 12, 2019
@bajtos bajtos mentioned this pull request Nov 12, 2019
3 tasks
@bajtos bajtos force-pushed the fix/lb4-artifact-discovery-missing-dir branch from a922255 to 0993d0f Compare November 12, 2019 16:04
);
});
} catch (err) {
if (err.code === 'ENOENT') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to check if the directory exists in advance instead of using the err code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that approach problematic, because it introduces a race condition - between the time we check if the directory exists, and the time we read the entries, the directory can be deleted or removed.

What are your concerns about my proposed approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to deal with the edge case where the directory is removed when the command in running. If so, we'll have to use sync fs apis.

My main concern is to rely on the error code. It would be more authoritative by calling an api to check existence of the directory.

It's not a blocker for the PR, anyway.

@bajtos bajtos requested a review from a team November 18, 2019 07:39
@@ -119,6 +117,21 @@ describe('lb4 model integration', () => {
basicModelFileChecks(expectedModelFile, expectedIndexFile);
});

it('creates "src/models" directory if it does no exist', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: does no exist -> does not exist

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it as part of rebase.

} catch (err) {
if (err.code === 'ENOENT') {
// Target directory was not found (e.g. "src/models" does not exist yet).
return [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: I assume if the target directory does not exist, it will get created when creating the artifact?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct.

Copy link
Member

@dhmlau dhmlau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please fix the typo mentioned in #4112 (comment).

When creating a new artifact (e.g. Model or Repository) while the target
directory does not exist yet (e.g. `src/models` or `src/repositories`),
we used to abort CLI with a ENOENT error.

This commit is fixing our CLI to treat the missing directory as if it
was empty and continue the operation if possible.

Signed-off-by: Miroslav Bajtoš <[email protected]>
@raymondfeng raymondfeng force-pushed the fix/lb4-artifact-discovery-missing-dir branch from 0993d0f to b86111d Compare November 25, 2019 18:47
@raymondfeng raymondfeng merged commit ba34838 into master Nov 25, 2019
@raymondfeng raymondfeng deleted the fix/lb4-artifact-discovery-missing-dir branch November 25, 2019 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants