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

improve user experience when reading files #357

Merged
merged 1 commit into from
Dec 13, 2021
Merged

Conversation

glommer
Copy link

@glommer glommer commented Dec 11, 2021

It took me a while now to figure out why chisel was returning simply
" stream did not contain valid UTF-8"

The reason is because I had temporary files inside the endpoints
directory, but our test is broken. It tests for the dentry.path(),
which ends up being something like "/endpoints/.temporary.swp".

Instead, it should test or dentry.filename(), which is just the last
part. Also, we can't really accept anything that starts with ".", so
we can simplify the test.

In case we do fail for any other reason, I'm also improving the message
by listing which file failed.

It took me a while now to figure out why chisel was returning simply
"    stream did not contain valid UTF-8"

The reason is because I had temporary files inside the endpoints
directory, but our test is broken. It tests for the dentry.path(),
which ends up being something like "/endpoints/.temporary.swp".

Instead, it should test or dentry.filename(), which is just the last
part. Also, we can't really accept anything that starts with ".", so
we can simplify the test.

In case we do fail for any other reason, I'm also improving the message
by listing which file failed.
@dekimir
Copy link
Contributor

dekimir commented Dec 12, 2021

I fixed the build of this branch as follows:

modified   cli/src/main.rs
@@ -72,7 +72,7 @@ fn dir_to_paths(dir: &Path, paths: &mut Vec<PathBuf>) -> anyhow::Result<()> {
         } else if !dentry
             .file_name()
             .to_str()
-            .map_or(false, |x| x.starts_with("."))
+            .map_or(false, |x| x.starts_with('.'))
         {
             // files with names that can't be converted wtih to_str() or that start with . are
             // ignored
@@ -189,7 +189,7 @@ fn read_to_string<P: AsRef<Path>>(filename: P) -> anyhow::Result<String> {
         let mut s = "".to_string();
         stdin()
             .read_to_string(&mut s)
-            .with_context(|| format!("while reading stdin"))?;
+            .with_context(|| "while reading stdin".to_string())?;
         Ok(s)
     } else {
         fs::read_to_string(filename.as_ref())

I also rebased on main and added a test.

.map_or(false, |x| x.starts_with('.'))
{
// files with names that can't be converted wtih to_str() or that start with . are
// ignored
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also ignore any file ending in tilde -- those are Emacs backup files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I did an explicit list of files because that's what nom, for example is doing. Of course, I did make the list as complete as npm does.

@glommer glommer merged commit 27ae2a0 into main Dec 13, 2021
@glommer glommer deleted the glauber.costa/userxp branch December 13, 2021 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants