There's a section of my code that has unexpected behaviour.
. . .
fmt.Println("Error:", err)
if err == nil {
return err
}
fmt.Println("Done category")
. . .
The section above has the following output
Error: <nil>
The code below if statement is never executed. If I remove the if statement the code behaves as expected.
Reference: https://github.com/skarllot/flogviewer/blob/master/wlog/parser.go#L138
Let's step through it.
fmt.Println("Error:", err)
If the output is Error: <nil>
.. then your err
variable is nil
.
if err == nil {
return err
}
This is saying .. "if the err
variable is nil
(which it is .. we established that above) ... then return the nil
value.
At this point .. your function has returned.. so nothing else below it will run.
Perhaps you meant this line instead?:
if err != nil {
// ^^ NOT equal?