github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/repository/errors.go (about) 1 package repository 2 3 import ( 4 "errors" 5 "fmt" 6 "strings" 7 ) 8 9 var ( 10 // ErrInvalidPublicKeySize will get thrown if a string is passed 11 // which couldn't be encoded to the correct size to pass it as a 12 // Public Key signature. 13 ErrInvalidPublicKeySize = errors.New("Invalid public key size.") 14 // ErrSignatureVerification gets returned if a signature of a signed NIB could 15 // not be verified. 16 ErrSignatureVerification = errors.New("Signature verification failed") 17 // ErrUnMarshalling gets returned if a NIB could not be extracted from stored 18 // bytes. 19 ErrUnMarshalling = errors.New("Couldn't extract item from byte stream") 20 // ErrTransactionNotExists is thrown if a transaction could not be found. This is used 21 // by the transaction manager. 22 ErrTransactionNotExists = errors.New("Transaction does not exist in repository.") 23 // ErrNIBConflict is returned when attempting to import a NIB 24 // which may not be fast-forwarded. 25 ErrNIBConflict = errors.New("NIB conflict (cannot fast forward)") 26 // ErrRefusingWorkOnDotLara is thrown when an attempt is made to add the 27 // management directory or some content to the repository. 28 ErrRefusingWorkOnDotLara = errors.New("will not work on .lara") 29 // ErrWorkDirConflict is being returned if a checkout path has changed data. 30 ErrWorkDirConflict = errors.New("workdir conflict") 31 ) 32 33 // NewErrNIBContentMissing returns a new ErrNIBContentMissing Error with the passed 34 // content IDs marked as missing. 35 func NewErrNIBContentMissing(contentIDs []string) *ErrNIBContentMissing { 36 return &ErrNIBContentMissing{ 37 contentIDs: contentIDs, 38 } 39 } 40 41 // ErrNIBContentMissing is returned when trying to add a NIB to the repository and 42 // content IDs are missing. 43 type ErrNIBContentMissing struct { 44 contentIDs []string 45 } 46 47 // Error returns the error message which encodes the not found content ID. 48 func (e *ErrNIBContentMissing) Error() string { 49 return fmt.Sprintf( 50 "Content of passed NIB is not stored yet. Missing contentIDs: %s", 51 strings.Join(e.contentIDs, ", "), 52 ) 53 } 54 55 // MissingContentIDs returns all ids which couldn't be resolved in the 56 // repository. 57 func (e *ErrNIBContentMissing) MissingContentIDs() []string { 58 return e.contentIDs 59 } 60 61 // IsNIBContentMissing checks if the passed error is a nibContentMissing error. 62 func IsNIBContentMissing(err error) bool { 63 switch err.(type) { 64 case nil: 65 return false 66 case *ErrNIBContentMissing: 67 return true 68 default: 69 return false 70 } 71 }