-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
a922255
to
0993d0f
Compare
); | ||
}); | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@@ -119,6 +117,21 @@ describe('lb4 model integration', () => { | |||
basicModelFileChecks(expectedModelFile, expectedIndexFile); | |||
}); | |||
|
|||
it('creates "src/models" directory if it does no exist', async () => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 []; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct.
There was a problem hiding this 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]>
0993d0f
to
b86111d
Compare
When creating a new artifact (e.g. Model or Repository) while the target directory does not exist yet (e.g.
src/models
orsrc/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 machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈