Read and work with errors
Closed this issue · 2 comments
rafi0101 commented
Hi. First of all I want to thank you for this project ;-)
I would like to know how to read your error messages and work with them.
The following scenario: I want to acquire a specific IP with AcquireSpecificIP()
and it could be possible that this IP is already acquired, but that's ok. So I would like to read the error message like this
_, err = ipam.Ipamer.AcquireSpecificIP(ctx, prefix, ip)
if err != nil {
if err == goipam.ErrAlreadyAllocated {
log.Warnln("this is ok")
} else {
log.Errorln(err)
return err
}
}
But this does not work as expected, since I could see the error message is an assembled string. Can you tell me how to work with Variables and your error messages?
majst01 commented
I guess you have to use (untested):
_, err = ipam.Ipamer.AcquireSpecificIP(ctx, prefix, ip)
if err != nil {
if errors.Is(err, goipam.ErrAlreadyAllocated) {
log.Warnln("this is ok")
} else {
log.Errorln(err)
return err
}
}
rafi0101 commented
Yes, that is how it works 👍
Thanks for the quick reply