~yerinalexey/rex

c875d9507f6d34bc27a31ea8669e3e1f1b0315b8 — Alexey Yerin 5 months ago fb2cf1a
Return error instead of crashing in fromFile
1 files changed, 9 insertions(+), 10 deletions(-)

M main.go
M main.go => main.go +9 -10
@@ 86,18 86,12 @@ 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)
	}
	raw, err := ioutil.ReadFile(fname)

	return data
	return string(raw), err
}

func main() {


@@ 128,7 122,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 == "" {