-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bad format error caused by negative duration #49
Conversation
Hi! Thanks for doing the work to write this patch, but since the server doesn’t support negative durations, I would argue it’s good for this situation to return an error. For example, maybe an application bug has resulted in an unintended negative duration; then it’ll be easier to find that bug if an error shows up. However, it would certainly help a lot more if a more specific & descriptive error could be returned instead of the general bad format error. It would also be nice to avoid an unnecessary round trip to the server in that case. How does that sound to you? |
Thanks for review. |
@kr |
Using a uint32 would remove the possibility of negative values, but it would introduce ambiguity about the units (seconds, milliseconds, etc) and it would be a breaking change. I think it’s better to stick with time.Duration, since that’s the standard way to represent a duration in Go. I think I’d prefer to see a check at the top of method Conn.cmd along these lines: for _, a := range args {
if d, _ := a.(time.Duration); d < 0 {
return req{}, fmt.Errorf("duration must be non-negative, got %v", d)
}
} This would still eliminate the need for the internal type dur, like you’ve already done in this change. |
Thanks for review and suggestions, good idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for your patience and perseverance!
Motivation
Fix issue #48
describe
bad format error occurred if
delay
orttr
is less than -1s.reproduce
cause
'-'
(-1s) is illegal char foruint32
, see prot.c#L1048Modification
dur.String()
replaced bydur2sec(time.Duration) string
utility function.