Handling errors

There is a central thesis in some programming language theories that errors in most programs happen at the boundary. While there are many interpretations of this thesis (boundaries of what? Some scholars think it's at the boundaries of functions; some think it's at the boundaries of computation), what is certainly true from experience is that boundaries of I/O are where the most errors happen. Hence, we have to be extra careful when dealing with input and output.

For the purposes of ingesting the files, we define an errList type as follows:

type errList []error

func (err errList) Error() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "Errors Found: ")
for _, e := range err {
fmt.Fprintf(&buf, " %v ", e)
}
return buf.String()
}

That way we can continue, even if an error happens while reading a file. The error will be bubbled back all the way to the top without causing any panic.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.14.93