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

fix: fix pricePerBroadcaster JSON file line breaks parsing bug #2913

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

### Bug Fixes 🐞

- \[#2913](https://github.com/livepeer/go-livepeer/issues/2912) fixes a bug that prevented `pricePerBroadcaster` JSON files with line-breaks from being parsed correctly (@rickstaa).

#### CLI

#### General
Expand Down
16 changes: 5 additions & 11 deletions common/readfromfile.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package common

import (
"bufio"
"fmt"
"os"
)
Expand All @@ -18,23 +17,18 @@ func ReadFromFile(s string) (string, error) {
if info.IsDir() {
// If the supplied string is a directory,
// assume it is the pass and return it
// along with an approptiate error.
// along with an appropriate error.
return s, fmt.Errorf("supplied path is a directory")
}
file, err := os.Open(s)
bytes, err := os.ReadFile(s)
if err != nil {
return s, err
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
txt := string(bytes)

scanner.Scan()
txtline := scanner.Text()
file.Close()

if len(txtline) == 0 {
if len(txt) == 0 {
return s, fmt.Errorf("supplied file is empty")
}

return txtline, nil
return txt, nil
}
Loading