github.com/storacha/go-ucanto@v0.7.2/server/datamodel/errors.go (about) 1 package datamodel 2 3 import ( 4 // for go:embed 5 _ "embed" 6 "fmt" 7 8 "github.com/ipld/go-ipld-prime" 9 "github.com/ipld/go-ipld-prime/schema" 10 ) 11 12 //go:embed errors.ipldsch 13 var errorsch []byte 14 15 var ( 16 errorTypeSystem *schema.TypeSystem 17 ) 18 19 func init() { 20 ts, err := ipld.LoadSchemaBytes(errorsch) 21 if err != nil { 22 panic(fmt.Errorf("failed to load IPLD schema: %w", err)) 23 } 24 errorTypeSystem = ts 25 } 26 27 func Schema() []byte { 28 return errorsch 29 } 30 31 func HandlerExecutionErrorType() schema.Type { 32 return errorTypeSystem.TypeByName("HandlerExecutionError") 33 } 34 35 type FailureModel struct { 36 Name *string 37 Message string 38 Stack *string 39 } 40 41 type CapabilityModel struct { 42 Can string 43 With string 44 } 45 46 type HandlerExecutionErrorModel struct { 47 Error bool 48 Name *string 49 Message string 50 Stack *string 51 Cause FailureModel 52 Capability CapabilityModel 53 } 54 55 func InvocationCapabilityErrorType() schema.Type { 56 return errorTypeSystem.TypeByName("InvocationCapabilityError") 57 } 58 59 type InvocationCapabilityErrorModel struct { 60 Error bool 61 Name *string 62 Message string 63 Capabilities []CapabilityModel 64 } 65 66 func HandlerNotFoundErrorType() schema.Type { 67 return errorTypeSystem.TypeByName("HandlerNotFoundError") 68 } 69 70 type HandlerNotFoundErrorModel struct { 71 Error bool 72 Name *string 73 Message string 74 Capability CapabilityModel 75 } 76 77 func InvalidAudienceErrorType() schema.Type { 78 return errorTypeSystem.TypeByName("InvalidAudienceError") 79 } 80 81 type InvalidAudienceErrorModel struct { 82 Error bool 83 Name *string 84 Message string 85 }