Cap ck_files::read at 64 MiB with typed TooLarge error #41
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/041-cap-ck-files-read-at-64-mib-with-typed-toolarg"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Cap ck_files::read at 64 MiB with typed TooLarge error
Along the way:
Touches 6 files:
ck-files/COVERAGE_EXEMPT.md,ck-files/README.md,ck-files/src/lib.rs,ck-files/tests/errors.rs,ck-files/tests/read_write.rs,ckeditor-files.md.I do not want to merge while the error path in
ck-files/tests/read_write.rsis silent. The rest is fine.@ -195,2 +240,4 @@/// ```pub fn read(path: &Path) -> Result<String, FileError> {let size = fs::metadata(path)?.len();if size > MAX_FILE_SIZE {I had to read
MAX_FILE_SIZEtwice. Nothing wrong with it, but one line of comment would save the next person the second read.@ -118,0 +166,4 @@assert_eq!(p, path);assert_eq!(size, over);}other => panic!("expected TooLarge, got {other:?}"),This panics. Is
otherunreachable, or unreachable today? If it is the second I would rather see an error the caller can handle.@ -55,0 +62,4 @@fn read_errors_on_a_directory_path() {let fx = Fixture::new();let path = fx.path("a-directory");std::fs::create_dir(&path).unwrap();stdunwraps here. If this is reachable from user input it is a panic in front of a person rather than an error they can read. Is it provably there at this point, or should it carry a??That is it for
ck-files/tests/read_write.rs. Thanks for the second pass.It is reachable. The function in
ck-files/tests/read_write.rsreturns a Result now and the caller reports it, so the unwrap onstdis gone.Unreachable today, which is not the same thing.
otherreturns an error variant now, andck-files/tests/errors.rshas a test that drives the path.Comment added on
MAX_FILE_SIZEinck-files/src/lib.rs. It was obvious when I wrote it and it will not be in a month.Done, and I added the test for
ck-files/tests/read_write.rsthat would have caught it.