| 1 |
package errors |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
) |
| 6 |
|
| 7 |
// noSuchObject is an error type that occurs when no object with a given object |
| 8 |
// ID is available. |
| 9 |
type noSuchObject struct { |
| 10 |
oid []byte |
| 11 |
} |
| 12 |
|
| 13 |
// Error implements the error.Error() function. |
| 14 |
func (e *noSuchObject) Error() string { |
| 15 |
return fmt.Sprintf("gitobj: no such object: %x", e.oid) |
| 16 |
} |
| 17 |
|
| 18 |
// NoSuchObject creates a new error representing a missing object with a given |
| 19 |
// object ID. |
| 20 |
func NoSuchObject(oid []byte) error { |
| 21 |
return &noSuchObject{oid: oid} |
| 22 |
} |
| 23 |
|
| 24 |
// IsNoSuchObject indicates whether an error is a noSuchObject and is non-nil. |
| 25 |
func IsNoSuchObject(e error) bool { |
| 26 |
err, ok := e.(*noSuchObject) |
| 27 |
return ok && err != nil |
| 28 |
} |