(BTW, sharing your code on play.golang.org makes it easier to format and 
read)

On Tuesday, 16 November 2021 at 14:11:54 UTC leam...@gmail.com wrote:

>
> 14 func exists(filepath string) bool { 
> 15 if _, err := os.Stat(filepath); errors.Is(err, fs.ErrNotExist) { 
> 16 return false 
> 17 } 
> 18 return true 
> 19 }


You are silently ignoring all errors here, apart from fs.ErrNotExist.  (You 
already identified that problem in your isDir function).

Basically there are three possible results: file exists, file doesn't 
exist, or something went wrong.  The traditional way to return that would 
be as a pair of values (bool, err)

Alternatively, it might be reasonable to panic(err) on any other non-nil 
error here.

 

> 42 if exists(*custom_datadir) { 
> 43 customData = isDir(*custom_datadir) 
> 44 }


Screams "pointer not checked for nil" to me.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2f2a5642-acd3-4dea-8806-ef225ea56964n%40googlegroups.com.

Reply via email to