validation(scaffold,companyos): reject regular-file target with clear message#13
Open
CryptoJones wants to merge 2 commits into
Open
validation(scaffold,companyos): reject regular-file target with clear message#13CryptoJones wants to merge 2 commits into
CryptoJones wants to merge 2 commits into
Conversation
… message If an operator typo'd socrates init my-project --base ~/notes.txt or otherwise passed a path that exists as a regular file, scaffold() and scaffold_companyos() previously hit confusing late-stage errors: - scaffold() got "NotADirectoryError: [Errno 20] Not a directory" from inside the FILES touch loop — after target.mkdir(exist_ok=overwrite) silently no-op'd on the existing-as-file path. - scaffold_companyos() blew up inside any(target.iterdir()) because Path.iterdir on a file raises NotADirectoryError mid-condition. Both now check `target.is_file()` up-front and raise a clean NotADirectoryError with an actionable message. The file is untouched. Tests added (3): - scaffold() rejects file target — no side effects - scaffold(file, overwrite=True) STILL rejects (overwrite is for empty dirs, not for silently clobbering user files) - scaffold_companyos() symmetric guard 150/150 tests pass; ruff + mypy clean.
Iter 12 added NotADirectoryError to scaffold_companyos but _cmd_companyos only caught FileExistsError, so passing a regular file path crashed with a stacktrace instead of returning 2 + a clean error message. Catch both errors in the same except clause. Test added: socrates companyos <file> returns 2 with 'error:' on stderr and leaves the file untouched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
5bc304a validation: catch NotADirectoryError in _cmd_companyos too (#cli)
Iter 12 added NotADirectoryError to scaffold_companyos but
_cmd_companyos only caught FileExistsError, so passing a regular
file path crashed with a stacktrace instead of returning 2 + a
clean error message. Catch both errors in the same except clause.
Test added: socrates companyos returns 2 with 'error:' on
stderr and leaves the file untouched.
051e424 validation(scaffold,companyos): reject regular-file target with clear message
If an operator typo'd
socrates init my-project --base ~/notes.txt
or otherwise passed a path that exists as a regular file, scaffold()
and scaffold_companyos() previously hit confusing late-stage errors:
inside the FILES touch loop — after target.mkdir(exist_ok=overwrite)
silently no-op'd on the existing-as-file path.
Path.iterdir on a file raises NotADirectoryError mid-condition.
Both now check
target.is_file()up-front and raise a cleanNotADirectoryError with an actionable message. The file is untouched.
Tests added (3):
empty dirs, not for silently clobbering user files)
150/150 tests pass; ruff + mypy clean.
This branch has TWO commits: