~yerinalexey/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH rex v2] Return possible error when reading from file

Details
Message ID
<20210112095250.52607-1-garrit@slashdev.space>
DKIM signature
missing
Download raw message
Patch: +9 -11
---
 main.go | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/main.go b/main.go
index a7e4786..65c762b 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("Failed to read %s: %v\n", file, err)
		}
	}

	if data == "" {
-- 
2.24.3 (Apple Git-128)
Details
Message ID
<20210112152939.chg4gyoxos2mvhbt@localhost>
In-Reply-To
<20210112095250.52607-1-garrit@slashdev.space> (view parent)
DKIM signature
pass
Download raw message
> -func fromFile(fname string) string {
> +func fromFile(fname string) (string, error) {

I just realized I don't really like the name of this function. Maybe
rename it to readFile or something?
Details
Message ID
<20210112153518.Horde.S0bR3YaCP87mlMKsBNH936f@home.garrit.xyz>
In-Reply-To
<20210112152939.chg4gyoxos2mvhbt@localhost> (view parent)
DKIM signature
missing
Download raw message
"Alexey Yerin" yerinalexey98fd@gmail.com – 12. Januar 2021 16:30
> I just realized I don't really like the name of this function. Maybe
> rename it to readFile or something?

Makes sense. One sec.
Reply to thread Export thread (mbox)