~yerinalexey/public-inbox

rex: Return possible error when reading from file v1 NEEDS REVISION

Garrit Franke: 1
 Return possible error when reading from file

 1 files changed, 9 insertions(+), 11 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~yerinalexey/public-inbox/patches/19501/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH rex] Return possible error when reading from file Export this patch

---
 main.go | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/main.go b/main.go
index a7e4786..c231570 100644
--- a/main.go
+++ b/main.go
@@ -86,18 +86,11 @@ func fromStdin() string {
	return data
}

func fromFile(fname string) string {
func fromFile(fname string) (string, error) {
	// TODO: This will block before file loads, should be in a separate
	// goroutine
	var data string

	if raw, err := ioutil.ReadFile(fname); err == nil {
		data = string(raw)
	} else {
		fatalf("Failed to read %s: %v\n", fname, err)
	}

	return data
	raw, err := ioutil.ReadFile(fname)
	return string(raw), err
}

func main() {
@@ -128,7 +121,12 @@ func main() {
	if file == "" {
		data = fromStdin()
	} else {
		data = fromFile(file)
		var err error
		data, err = fromFile(file)

		if err != nil {
			fatalf("%v\n", err)
		}
	}

	if data == "" {
-- 
2.24.3 (Apple Git-128)