From 6acbeb4dcbaf667392b8ea21f57b026ead3c9f26 Mon Sep 17 00:00:00 2001 From: Jim Zhang Date: Sun, 1 Jan 2023 15:37:38 -0500 Subject: [PATCH 1/3] Add custom error support for FFI Signed-off-by: Jim Zhang --- mocks/authmocks/plugin.go | 2 +- mocks/dbmigratemocks/driver.go | 2 +- mocks/httpservermocks/go_http_server.go | 2 +- pkg/fftypes/ffi.go | 16 ++++++++++++++++ pkg/fftypes/ffi_test.go | 13 +++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/mocks/authmocks/plugin.go b/mocks/authmocks/plugin.go index d103d66..c71c8b9 100644 --- a/mocks/authmocks/plugin.go +++ b/mocks/authmocks/plugin.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.1. DO NOT EDIT. +// Code generated by mockery v2.15.0. DO NOT EDIT. package authmocks diff --git a/mocks/dbmigratemocks/driver.go b/mocks/dbmigratemocks/driver.go index 23ac9ae..ad9ca1e 100644 --- a/mocks/dbmigratemocks/driver.go +++ b/mocks/dbmigratemocks/driver.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.1. DO NOT EDIT. +// Code generated by mockery v2.15.0. DO NOT EDIT. package dbmigratemocks diff --git a/mocks/httpservermocks/go_http_server.go b/mocks/httpservermocks/go_http_server.go index 749f64a..710e25b 100644 --- a/mocks/httpservermocks/go_http_server.go +++ b/mocks/httpservermocks/go_http_server.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.1. DO NOT EDIT. +// Code generated by mockery v2.15.0. DO NOT EDIT. package httpservermocks diff --git a/pkg/fftypes/ffi.go b/pkg/fftypes/ffi.go index 5d9c38e..a2f8db1 100644 --- a/pkg/fftypes/ffi.go +++ b/pkg/fftypes/ffi.go @@ -46,6 +46,7 @@ type FFI struct { Version string `ffstruct:"FFI" json:"version"` Methods []*FFIMethod `ffstruct:"FFI" json:"methods,omitempty"` Events []*FFIEvent `ffstruct:"FFI" json:"events,omitempty"` + Errors []*FFIError `ffstruct:"FFI" json:"errors,omitempty"` } type FFIMethod struct { @@ -76,6 +77,21 @@ type FFIEvent struct { FFIEventDefinition } +type FFIErrorDefinition struct { + Name string `ffstruct:"FFIError" json:"name"` + Description string `ffstruct:"FFIError" json:"description"` + Params FFIParams `ffstruct:"FFIError" json:"params"` +} + +type FFIError struct { + ID *UUID `ffstruct:"FFIError" json:"id,omitempty" ffexcludeinput:"true"` + Interface *UUID `ffstruct:"FFIError" json:"interface,omitempty" ffexcludeinput:"true"` + Namespace string `ffstruct:"FFIError" json:"namespace,omitempty" ffexcludeinput:"true"` + Pathname string `ffstruct:"FFIError" json:"pathname,omitempty" ffexcludeinput:"true"` + Signature string `ffstruct:"FFIError" json:"signature" ffexcludeinput:"true"` + FFIErrorDefinition +} + type FFIParam struct { Name string `ffstruct:"FFIParam" json:"name"` Schema *JSONAny `ffstruct:"FFIParam" json:"schema,omitempty"` diff --git a/pkg/fftypes/ffi_test.go b/pkg/fftypes/ffi_test.go index e80937c..33c5d4c 100644 --- a/pkg/fftypes/ffi_test.go +++ b/pkg/fftypes/ffi_test.go @@ -62,6 +62,19 @@ func TestValidateFFI(t *testing.T) { }, }, }, + Errors: []*FFIError{ + { + FFIErrorDefinition: FFIErrorDefinition{ + Name: "mathError", + Params: []*FFIParam{ + { + Name: "badOperand", + Schema: JSONAnyPtr(`{"type": "integer"}, "details": {"type": "uint256"}`), + }, + }, + }, + }, + }, } err := ffi.Validate(context.Background(), true) assert.NoError(t, err) From 8932a57f77674a1a5b75f9a8e2c267e43d0e80ea Mon Sep 17 00:00:00 2001 From: Jim Zhang Date: Sun, 1 Jan 2023 15:42:22 -0500 Subject: [PATCH 2/3] Update copyright header Signed-off-by: Jim Zhang --- pkg/fftypes/ffi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/fftypes/ffi.go b/pkg/fftypes/ffi.go index a2f8db1..fae5e77 100644 --- a/pkg/fftypes/ffi.go +++ b/pkg/fftypes/ffi.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2023, 2022 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // From 54c51d11bb09b061f0071d566ce38f90da84f34b Mon Sep 17 00:00:00 2001 From: Jim Zhang Date: Sun, 1 Jan 2023 15:46:54 -0500 Subject: [PATCH 3/3] Update copyright header Signed-off-by: Jim Zhang --- pkg/fftypes/ffi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/fftypes/ffi.go b/pkg/fftypes/ffi.go index fae5e77..e59db51 100644 --- a/pkg/fftypes/ffi.go +++ b/pkg/fftypes/ffi.go @@ -1,4 +1,4 @@ -// Copyright © 2023, 2022 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 //