Since the skip value is always 2, and its probably guaranteed that runtime.Caller() will not fail due to skip being greater than number of stack frames. But I think could fail due to some unexpected issues - something specific to user system, or some memory corruption.
I think, it shouldn't hurt to add a check for the ok value, in case it is false, for a more complete error handling.
func Caller(skip int) (pc uintptr, file string, line int, ok bool)
The boolean ok is false if it was not possible to recover the information.
Reference :
Since the
skipvalue is always2, and its probably guaranteed thatruntime.Caller()will not fail due toskipbeing greater than number of stack frames. But I think could fail due to some unexpected issues - something specific to user system, or some memory corruption.I think, it shouldn't hurt to add a check for the ok value, in case it is false, for a more complete error handling.
Reference :