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

[Bug]: Fabric ignores lines without trailing newline on stdin #1057

Open
1 task done
kolewu opened this issue Oct 19, 2024 · 2 comments
Open
1 task done

[Bug]: Fabric ignores lines without trailing newline on stdin #1057

kolewu opened this issue Oct 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@kolewu
Copy link

kolewu commented Oct 19, 2024

What happened?

A line without a trailing newline will be ignored:

echo -n "light nuts wall" | fabric --dry-run

No user input is sent:

Dry run: Would send the following request:
Options:

With a trailing newline it works:

echo "light nuts wall" | fabric --dry-run

User input is sent:

Dry run: Would send the following request:
User:
light nuts wall

Options:

Version check

  • Yes I was.

Relevant log output

No response

Relevant screenshots (optional)

No response

@kolewu kolewu added the bug Something isn't working label Oct 19, 2024
@kolewu
Copy link
Author

kolewu commented Oct 19, 2024

Fix is so simple that I don't want to make a MR for it. Just add the data up to EOF when reading stdin. That is in cli/flags.go in function readStdin():

 // readStdin reads from stdin and returns the input as a string or an error
 func readStdin() (string, error) {
     reader := bufio.NewReader(os.Stdin)
     var input string
     for {
         line, err := reader.ReadString('\n')
+        input += line
          if err != nil {
             if errors.Is(err, io.EOF) {
                 break
             }
             return "", fmt.Errorf("error reading from stdin: %w", err)
         }
-        input += line
     }
     return input, nil
 }

Since I'm just a Go beginner, I'm not sure, if line must be checked before using it.

This change fixes the described problem and also #917.

@techjp
Copy link

techjp commented Oct 24, 2024

I thought I was going insane when experiencing this problem after migrating from the old Python version of Fabric to the new Go version!

For those who do not wish to change the code, you can do this as a workaround until the bug is fixed:

(cat <filename here>; echo "") | fabric <rest of fabric command>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants