github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/istructsmem/validation-errors.go (about) 1 /* 2 * Copyright (c) 2021-present Sigma-Soft, Ltd. 3 * @author: Nikolay Nikitin 4 */ 5 6 package istructsmem 7 8 import "fmt" 9 10 // validate error codes, see ValidateError.Code() 11 const ( 12 ECode_UnknownError = iota 13 14 ECode_EmptyTypeName 15 ECode_InvalidTypeName 16 ECode_InvalidTypeKind 17 18 ECode_EmptyData 19 20 ECode_InvalidRecordID 21 ECode_InvalidRefRecordID 22 23 ECode_EEmptyCUDs 24 25 ECode_InvalidChildName 26 ECode_InvalidOccursMin 27 ECode_InvalidOccursMax 28 ) 29 30 type validateErrorType struct { 31 error 32 code int 33 } 34 35 func (e validateErrorType) Code() int { 36 return e.code 37 } 38 39 func (e validateErrorType) Unwrap() error { 40 return e.error 41 } 42 43 func validateError(code int, err error) ValidateError { 44 e := validateErrorType{ 45 error: fmt.Errorf("%w; validate error code: %d", err, code), 46 code: code, 47 } 48 return e 49 } 50 51 func validateErrorf(code int, format string, a ...interface{}) ValidateError { 52 return validateError(code, fmt.Errorf(format, a...)) 53 } 54 55 const ( 56 // These errors are possible while checking raw identifiers specified in the event arguments and CUDs 57 errRepeatedID = "%v repeatedly uses record ID «%d» in %v: %w" 58 errRequiredRawID = "%v should use raw record ID (not «%d») in created %v: %w" 59 errUnexpectedRawID = "%v unexpectedly uses raw record ID «%d» in updated %v: %w" 60 errRepeatedSingletonCreation = "%v repeatedly creates the same singleton %v (raw record ID «%d» and «%d»): %w" 61 errUnknownIDRef = "%v field «%s» refers to unknown record ID «%d»: %w" 62 errUnavailableTargetRef = "%v field «%s» refers to record ID «%d» that has unavailable target QName «%s»: %w" 63 errParentHasNoContainer = "%v has parent ID «%d» refers to «%s», which has no container «%s»: %w" 64 errParentContainerOtherType = "%v has parent ID «%d» refers to «%s», which container «%s» has another QName «%s»: %w" 65 ) 66 67 const ( 68 // These errors are possible while checking type and content of the event arguments and CUDs 69 errEventArgUseWrongType = "%v argument uses wrong type «%v», expected «%v»: %w" 70 errEventUnloggedArgUseWrongType = "%v unlogged argument uses wrong type «%v», expected «%v»: %w" 71 errContainerMinOccursViolated = "%v container «%s» has not enough occurrences (%d, minimum %d): %w" 72 errContainerMaxOccursViolated = "%v container «%s» has too many occurrences (%d, maximum %d): %w" 73 errUnknownContainerName = "%v child[%d] has unknown container name «%s»: %w" 74 errWrongContainerType = "%v child[%d] %v has wrong type name, expected «%v»: %w" 75 errWrongParentID = "%v child[%d] %v has wrong parent id «%d», expected «%d»: %w" 76 errEmptyRequiredField = "%v misses required field «%s»: %w" 77 errNullInRequiredRefField = "%v required ref field «%s» has NullRecordID value: %w" 78 errCUDsMissed = "%v must have not empty CUDs: %w" 79 errInvalidTypeKindInCUD = "%v CUD.%s() [record ID «%d»] %v has invalid type kind: %w" 80 )