-
Notifications
You must be signed in to change notification settings - Fork 67
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
Return golang errors instead of nvml.Return values #125
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
Your two example's in the description are the same .. I think you wanted one of them to check euqility instead of using That said -- what will happen if someone does do |
current, pending, err := device.GetMigMode() | ||
if errors.Is(err, nvml.ERROR_NOT_SUPPORTED) { | ||
fmt.Printf("MIG is not supported for device %v\n", i) | ||
|
||
} else if err != nil { | ||
log.Fatalf("Error getting MIG mode for device at index %d: %v", i, err) | ||
} | ||
fmt.Printf("MIG mode for device %v: current=%v pending=%v\n", i, current, pending) |
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.
Can we change this to:
current, pending, err := device.GetMigMode()
if err == nil {
fmt.Printf("MIG mode for device %v: current=%v pending=%v\n", i, current, pending)
continue
}
if errors.Is(err, nvml.ERROR_NOT_SUPPORTED) {
fmt.Printf("MIG is not supported for device %v\n", i)
continue
}
log.Fatalf("Error getting MIG mode for device at index %d: %v", i, err)
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.
None of the changes in this file look intentional...
func (l *library) ErrorString(r Return) string { | ||
return r.Error() | ||
return r.String() | ||
} |
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.
How does an end-user ever get ahold of a Return
value to pass it to this function?
These changes move from using
nvml.Return
values to using native Golangerror
values, making code more idiomatic.Note that this requires that
error.Is
is used instead of checking for equality in the returned value.For example:
would become: