diff --git a/contracts/proto/error/v1/error.proto b/contracts/proto/error/v1/error.proto new file mode 100644 index 000000000..485abe431 --- /dev/null +++ b/contracts/proto/error/v1/error.proto @@ -0,0 +1,32 @@ +syntax = "proto3"; +package nitric.error.v1; + +// protoc plugin options for code generation +option go_package = "nitric/v1;v1"; +option java_package = "io.nitric.proto.error.v1"; +option java_multiple_files = true; +option java_outer_classname = "Errors"; +option php_namespace = "Nitric\\Proto\\Error\\V1"; +option csharp_namespace = "Nitric.Proto.Error.v1"; + +message ErrorScope { + // The API service invoked, e.g. 'Service.Method'. + string service = 1; + + // The plugin method invoked, e.g. 'PluginService.Method'. + string plugin = 2; + + // The plugin method arguments, ensure only non-sensitive data is specified. + map args = 3; +} + +message ErrorDetails { + // The developer error message, explaining the error and ideally solution. + string message = 1; + + // The error root cause. + string cause = 2; + + // The scope of the error. + ErrorScope scope = 3; +} \ No newline at end of file diff --git a/go.sum b/go.sum index 9661fc7fb..bf43d2d59 100644 --- a/go.sum +++ b/go.sum @@ -22,10 +22,8 @@ cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNF cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= -cloud.google.com/go/bigquery v1.8.0 h1:PQcPefKFdaIzjQFbiyOgAqyx8q5djaE7x9Sqe712DPA= cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/datastore v1.1.0 h1:/May9ojXjRkPBNVrq+oWLqmWCkr4OU5uRY29bu0mRyQ= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= cloud.google.com/go/firestore v1.5.0 h1:4qNItsmc4GP6UOZPGemmHY4ZfPofVhcaKXsYw9wm9oA= cloud.google.com/go/firestore v1.5.0/go.mod h1:c4nNYR1qdq7eaZ+jSc5fonrQN2k3M7sWATcYTiakjEo= @@ -40,7 +38,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0 h1:STgFzyU5/8miMl0//zKh2aQeTyeaUH3WN9bSUiJ09bA= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9 h1:VpgP7xuJadIUuKccphEpTJnWhS2jkQyMt6Y7pJCD7fY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-sdk-for-go v51.3.0+incompatible h1:Y3wR7C5Sj0nZG3VhkePF5hK7zNCS5yeImN/k2CWB+u8= github.com/Azure/azure-sdk-for-go v51.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= @@ -60,9 +57,7 @@ github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+Z github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/zstd v1.4.8 h1:Rpmta4xZ/MgZnriKNd24iZMhGpP5dvUcs/uqfBapKZY= github.com/DataDog/zstd v1.4.8/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= @@ -80,19 +75,13 @@ github.com/aws/aws-sdk-go v1.36.12 h1:YJpKFEMbqEoo+incs5qMe61n1JH3o4O1IMkMexLzJG github.com/aws/aws-sdk-go v1.36.12/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/bmatcuk/doublestar/v4 v4.0.2 h1:X0krlUVAVmtr2cRoTqR8aDMrDqnB36ht8wpWTiQ3jsA= github.com/bmatcuk/doublestar/v4 v4.0.2/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= -github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403 h1:cqQfy1jclcSy/FwLjemeg3SR1yaINm74aQyupQ0Bl8M= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= @@ -104,9 +93,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad h1:EmNYJhPYy0pOFjCx2PrgtaBXmee0iUX9hLlxE1xHOJE= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.6.1 h1:4CF52PCseTFt4bE+Yk3dIpdVi7XWuPVMhPtm4FaIJPM= github.com/envoyproxy/protoc-gen-validate v0.6.1/go.mod h1:txg5va2Qkip90uYoSKH+nkAAmXrb2j3iq4FLwdrCbXQ= @@ -115,10 +102,8 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4 h1:WtGNWLvXpe6ZudgnXrq0barxBImvnnJoMEhXAzcbM0I= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -148,7 +133,6 @@ github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWe github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -182,18 +166,9 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/addlicense v0.0.0-20210428195630-6d92264d7170 h1:jLUa4MO3autxlRJmC4KubeE5QGIb5JqW9oEaqYTb/fA= -github.com/google/addlicense v0.0.0-20210428195630-6d92264d7170/go.mod h1:EMjYTRimagHs1FwlIqKyX3wAM0u3rA+McvlIIWmSamA= -github.com/google/addlicense v0.0.0-20210727174409-874627749a46 h1:1locMH9PVZH3LXvogcvdTxf2/9J4YT/9W3BSXrTN4/U= -github.com/google/addlicense v0.0.0-20210727174409-874627749a46/go.mod h1:EMjYTRimagHs1FwlIqKyX3wAM0u3rA+McvlIIWmSamA= -github.com/google/addlicense v0.0.0-20210729153508-ef04bb38a16b h1:KwI0NOpYd3rzKojfjeRerF7rzjeTwvJARVsgGf5TWmY= -github.com/google/addlicense v0.0.0-20210729153508-ef04bb38a16b/go.mod h1:EMjYTRimagHs1FwlIqKyX3wAM0u3rA+McvlIIWmSamA= -github.com/google/addlicense v0.0.0-20210810170408-9cc7ec3e36ab h1:+qfOxKbnAqDNCoFUNHxudKs8Z14T5EBYntAeWIeI1eA= -github.com/google/addlicense v0.0.0-20210810170408-9cc7ec3e36ab/go.mod h1:Sm/DHu7Jk+T5miFHHehdIjbi4M5+dJDRS3Cq0rncIxA= github.com/google/addlicense v1.0.0 h1:cqvo5suPWlsk6r6o42Fs2K66xYCl2tnhVPUYoP3EnO4= github.com/google/addlicense v1.0.0/go.mod h1:Sm/DHu7Jk+T5miFHHehdIjbi4M5+dJDRS3Cq0rncIxA= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -222,9 +197,7 @@ github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2 h1:LR89qFljJ48s990kEKGsk213yIJDPI4205OKOzbURK8= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -236,14 +209,11 @@ github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI= github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7 h1:ux/56T2xqZO/3cP1I2F86qpeoYPCOzk+KF/UH/Ar+lk= github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639 h1:mV02weKRL81bEnm8A0HT1/CAelMQDBuQIfLw8n+d6xI= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -256,18 +226,15 @@ github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfE github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= -github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.11.8 h1:difgzQsp5mdAz9v8lm3P/I+EpDKMU/6uTMw1y1FObuo= github.com/klauspost/compress v1.11.8/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -303,15 +270,12 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -327,7 +291,6 @@ github.com/spf13/afero v1.3.4 h1:8q6vk3hthlpb2SouZcnBVKboxWQWMDNF38bwholZrJc= github.com/spf13/afero v1.3.4/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -336,6 +299,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= @@ -348,7 +312,6 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.23.0 h1:0ufwSD9BhWa6f8HWdmdq4FHQ23peRo3Ng/Qs8m5NcFs= github.com/valyala/fasthttp v1.23.0/go.mod h1:0mw2RjXGOzxf4NL2jni3gUQ7LfjjUSiG5sskOUUSEpU= -github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -364,7 +327,6 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5 h1:dPmz1Snjq0kmkz159iL7S6WzdahUTHnHB5M56WFVifs= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= @@ -398,10 +360,8 @@ golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= -golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 h1:QE6XYQK6naiK1EPAe1g/ILLxN5RBoH5xkJk3CqlMI/Y= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -417,7 +377,6 @@ golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPI golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= @@ -537,7 +496,6 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -549,7 +507,6 @@ golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -711,9 +668,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= @@ -733,11 +688,7 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -rsc.io/binaryregexp v0.2.0 h1:HfqmD5MEmC0zvwBuF187nq9mdnXjXsSivRiXN7SmRkE= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/quote/v3 v3.1.0 h1:9JKUTTIUgS6kzR9mK1YuGKv6Nl+DijDNIc0ghT58FaY= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/pkg/adapters/grpc/errors.go b/pkg/adapters/grpc/errors.go index 46c72bab7..385184cf7 100644 --- a/pkg/adapters/grpc/errors.go +++ b/pkg/adapters/grpc/errors.go @@ -15,6 +15,10 @@ package grpc import ( + "fmt" + "reflect" + + v1 "github.com/nitric-dev/membrane/interfaces/nitric/v1" "github.com/nitric-dev/membrane/pkg/plugins/errors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -23,17 +27,109 @@ import ( // Provides GRPC error reporting func NewGrpcError(operation string, err error) error { if pe, ok := err.(*errors.PluginError); ok { - return newGrpcErrorWithCode(codes.Code(errors.Code(pe)), operation, pe) + code := codes.Code(errors.Code(pe)) + + ed := &v1.ErrorDetails{} + ed.Message = pe.Msg + if pe.Cause != nil { + ed.Cause = pe.Cause.Error() + } + ed.Scope = &v1.ErrorScope{ + Service: operation, + Plugin: pe.Plugin, + } + if len(pe.Args) > 0 { + args := make(map[string]string) + for k, v := range pe.Args { + args[k] = LogArg(v) + } + ed.Scope.Args = args + } + + s := status.New(code, pe.Msg) + s, _ = s.WithDetails(ed) + + return s.Err() + } else { return newGrpcErrorWithCode(codes.Internal, operation, err) } } func newGrpcErrorWithCode(code codes.Code, operation string, err error) error { - return status.Errorf(code, "%s: %v", operation, err) + ed := &v1.ErrorDetails{} + ed.Message = err.Error() + ed.Scope = &v1.ErrorScope{ + Service: operation, + } + + s := status.New(code, err.Error()) + s, _ = s.WithDetails(ed) + + return s.Err() } // Provides generic error for unregistered plugins func NewPluginNotRegisteredError(plugin string) error { - return status.Errorf(codes.Unimplemented, "%s plugin not registered", plugin) + ed := &v1.ErrorDetails{} + ed.Message = fmt.Sprintf("%s plugin not registered", plugin) + + s := status.New(codes.Unimplemented, ed.Message) + s, _ = s.WithDetails(ed) + + return s.Err() +} + +func LogArg(arg interface{}) string { + value := getValue(arg) + + if value.Kind() == reflect.Struct { + + str := "{" + for i := 0; i < value.NumField(); i++ { + + fieldType := value.Type().Field(i) + tag := fieldType.Tag.Get("log") + if tag == "" || tag == "-" { + continue + } + + if len(str) > 1 { + str += ", " + } + + field := value.Field(i) + str += fieldType.Name + ": " + LogArg(field.Interface()) + } + str += "}" + + return str + + } else if value.Kind() == reflect.Map { + str := "{" + + for k, v := range arg.(map[string]interface{}) { + if len(str) > 1 { + str += ", " + } + str += fmt.Sprintf("%v", k) + ": " + LogArg(v) + } + + str += "}" + + return str + + } else { + return fmt.Sprintf("%v", arg) + } +} + +func getValue(x interface{}) reflect.Value { + val := reflect.ValueOf(x) + + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + + return val } diff --git a/pkg/adapters/grpc/errors_test.go b/pkg/adapters/grpc/errors_test.go index 9497249f8..ed4a705f9 100644 --- a/pkg/adapters/grpc/errors_test.go +++ b/pkg/adapters/grpc/errors_test.go @@ -24,25 +24,50 @@ import ( . "github.com/onsi/gomega" ) +type SecretValue struct { + Type string `log:"Type"` + Factor int `log:"-"` + Value string +} + +type Secret struct { + Name string `json:"Name" log:"Name"` + Version string `json:"Version" log:"Version"` + Value *SecretValue `json:"Value" log:"Value"` +} + var _ = Describe("GRPC Errors", func() { Context("GrpcError", func() { When("plugin.errors.InvalidArgument", func() { It("Should report GRPC IllegalArgument error", func() { - newErr := errors.ErrorsWithScope("test") + newErr := errors.ErrorsWithScope("test", nil) + err := newErr( + codes.InvalidArgument, + "bad param", + nil, + ) + grpcErr := grpc.NewGrpcError("BadServer.BadCall", err) + Expect(grpcErr.Error()).To(ContainSubstring("rpc error: code = InvalidArgument desc = bad param")) + }) + }) + When("plugin.errors.InvalidArgument args", func() { + It("Should report GRPC IllegalArgument error with args", func() { + args := map[string]interface{}{"key": "value"} + newErr := errors.ErrorsWithScope("test", args) err := newErr( codes.InvalidArgument, "bad param", nil, ) grpcErr := grpc.NewGrpcError("BadServer.BadCall", err) - Expect(grpcErr.Error()).To(ContainSubstring("rpc error: code = InvalidArgument desc = BadServer.BadCall: test([]): bad param")) + Expect(grpcErr.Error()).To(ContainSubstring("rpc error: code = InvalidArgument desc = bad param")) }) }) When("Standard Error", func() { It("Should report GRPC Internal error", func() { err := fmt.Errorf("internal error") err = grpc.NewGrpcError("BadServer.BadCall", err) - Expect(err.Error()).To(ContainSubstring("rpc error: code = Internal desc = BadServer.BadCall: internal error")) + Expect(err.Error()).To(ContainSubstring("rpc error: code = Internal desc = internal error")) }) }) }) @@ -55,4 +80,70 @@ var _ = Describe("GRPC Errors", func() { }) }) }) + + Context("Logging Arg", func() { + When("string", func() { + It("return string value", func() { + Expect(grpc.LogArg("string")).To(BeEquivalentTo("string")) + }) + }) + + When("int", func() { + It("return string value", func() { + Expect(grpc.LogArg(123)).To(BeEquivalentTo("123")) + }) + }) + + When("bool", func() { + It("return string value", func() { + Expect(grpc.LogArg(true)).To(BeEquivalentTo("true")) + }) + }) + + When("float", func() { + It("return string value", func() { + Expect(grpc.LogArg(3.1415)).To(BeEquivalentTo("3.1415")) + }) + }) + + When("struct", func() { + It("return string value", func() { + + data := Secret{ + Name: "name", + Version: "3", + Value: &SecretValue{ + Type: "key", + Factor: 2, + Value: "2a4wijgPq0PpwJ76IjT7&lTBZ$5SGRcq", + }, + } + + value := grpc.LogArg(data) + Expect(value).To(BeEquivalentTo("{Name: name, Version: 3, Value: {Type: key}}")) + }) + }) + + When("map", func() { + It("return string value", func() { + secret := Secret{ + Name: "name", + Version: "3", + Value: &SecretValue{ + Type: "key", + Factor: 2, + Value: "2a4wijgPq0PpwJ76IjT7&lTBZ$5SGRcq", + }, + } + + valueMap := map[string]interface{}{ + "key": "value", + "secret": secret, + } + value := grpc.LogArg(valueMap) + Expect(value).To(ContainSubstring("secret: {Name: name, Version: 3, Value: {Type: key}}")) + Expect(value).To(ContainSubstring("key: value")) + }) + }) + }) }) diff --git a/pkg/adapters/grpc/event_grpc_test.go b/pkg/adapters/grpc/event_grpc_test.go index 9cb3d4998..83f0ae400 100644 --- a/pkg/adapters/grpc/event_grpc_test.go +++ b/pkg/adapters/grpc/event_grpc_test.go @@ -16,7 +16,6 @@ package grpc_test import ( "context" - "fmt" "github.com/nitric-dev/membrane/pkg/adapters/grpc" @@ -36,7 +35,6 @@ type MockEventService struct { } func (m *MockEventService) Publish(topic string, event *events.NitricEvent) error { - fmt.Printf("Publish called %v", event) m.PublishTopic = topic m.PublishEvent = event return m.PublishError diff --git a/pkg/plugins/document/boltdb/boltdb.go b/pkg/plugins/document/boltdb/boltdb.go index 26554516f..3dce599de 100644 --- a/pkg/plugins/document/boltdb/boltdb.go +++ b/pkg/plugins/document/boltdb/boltdb.go @@ -59,7 +59,9 @@ func (d BoltDoc) String() string { func (s *BoltDocService) Get(key *document.Key) (*document.Document, error) { newErr := errors.ErrorsWithScope( "BoltDocService.Get", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -105,7 +107,9 @@ func (s *BoltDocService) Get(key *document.Key) (*document.Document, error) { func (s *BoltDocService) Set(key *document.Key, content map[string]interface{}) error { newErr := errors.ErrorsWithScope( "BoltDocService.Set", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -151,7 +155,9 @@ func (s *BoltDocService) Set(key *document.Key, content map[string]interface{}) func (s *BoltDocService) Delete(key *document.Key) error { newErr := errors.ErrorsWithScope( "BoltDocService.Delete", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -212,7 +218,9 @@ func (s *BoltDocService) Delete(key *document.Key) error { func (s *BoltDocService) Query(collection *document.Collection, expressions []document.QueryExpression, limit int, pagingToken map[string]string) (*document.QueryResult, error) { newErr := errors.ErrorsWithScope( "BoltDocService.Query", - fmt.Sprintf("collection=%v", collection), + map[string]interface{}{ + "collection": collection, + }, ) if err := document.ValidateQueryCollection(collection); err != nil { diff --git a/pkg/plugins/document/dynamodb/dynamodb.go b/pkg/plugins/document/dynamodb/dynamodb.go index 31db0205e..068728a37 100644 --- a/pkg/plugins/document/dynamodb/dynamodb.go +++ b/pkg/plugins/document/dynamodb/dynamodb.go @@ -47,7 +47,9 @@ type DynamoDocService struct { func (s *DynamoDocService) Get(key *document.Key) (*document.Document, error) { newErr := errors.ErrorsWithScope( "DynamoDocService.Get", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) err := document.ValidateKey(key) @@ -119,7 +121,9 @@ func (s *DynamoDocService) Get(key *document.Key) (*document.Document, error) { func (s *DynamoDocService) Set(key *document.Key, value map[string]interface{}) error { newErr := errors.ErrorsWithScope( "DynamoDocService.Set", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -175,7 +179,9 @@ func (s *DynamoDocService) Set(key *document.Key, value map[string]interface{}) func (s *DynamoDocService) Delete(key *document.Key) error { newErr := errors.ErrorsWithScope( "DynamoDocService.Delete", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -258,7 +264,9 @@ func (s *DynamoDocService) Delete(key *document.Key) error { func (s *DynamoDocService) Query(collection *document.Collection, expressions []document.QueryExpression, limit int, pagingToken map[string]string) (*document.QueryResult, error) { newErr := errors.ErrorsWithScope( "DynamoDocService.Query", - fmt.Sprintf("collection=%v", collection), + map[string]interface{}{ + "collection": collection, + }, ) if err := document.ValidateQueryCollection(collection); err != nil { diff --git a/pkg/plugins/document/firestore/firestore.go b/pkg/plugins/document/firestore/firestore.go index cb8c47818..e38d06a27 100644 --- a/pkg/plugins/document/firestore/firestore.go +++ b/pkg/plugins/document/firestore/firestore.go @@ -43,7 +43,9 @@ type FirestoreDocService struct { func (s *FirestoreDocService) Get(key *document.Key) (*document.Document, error) { newErr := errors.ErrorsWithScope( "FirestoreDocService.Get", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -79,7 +81,9 @@ func (s *FirestoreDocService) Get(key *document.Key) (*document.Document, error) func (s *FirestoreDocService) Set(key *document.Key, value map[string]interface{}) error { newErr := errors.ErrorsWithScope( "FirestoreDocService.Set", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -114,7 +118,9 @@ func (s *FirestoreDocService) Set(key *document.Key, value map[string]interface{ func (s *FirestoreDocService) Delete(key *document.Key) error { newErr := errors.ErrorsWithScope( "FirestoreDocService.Delete", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -182,7 +188,9 @@ func (s *FirestoreDocService) Delete(key *document.Key) error { func (s *FirestoreDocService) Query(collection *document.Collection, expressions []document.QueryExpression, limit int, pagingToken map[string]string) (*document.QueryResult, error) { newErr := errors.ErrorsWithScope( "FirestoreDocService.Query", - fmt.Sprintf("collection=%v", collection), + map[string]interface{}{ + "collection": collection, + }, ) if err := document.ValidateQueryCollection(collection); err != nil { diff --git a/pkg/plugins/document/mongodb/mongodb.go b/pkg/plugins/document/mongodb/mongodb.go index 3e99251b0..5211b0412 100644 --- a/pkg/plugins/document/mongodb/mongodb.go +++ b/pkg/plugins/document/mongodb/mongodb.go @@ -37,8 +37,8 @@ const ( mongoDBSetDirectEnvVarName = "MONGODB_DIRECT" primaryKeyAttr = "_id" - parentKeyAttr = "_parent_id" - childrenAttr = "_child_colls" + parentKeyAttr = "_parent_id" + childrenAttr = "_child_colls" ) // Mapping to mongo operators, startsWith will be handled within the function @@ -51,11 +51,9 @@ var mongoOperatorMap = map[string]string{ ">": "$gt", } - - type MongoDocService struct { client *mongo.Client - db *mongo.Database + db *mongo.Database context context.Context document.UnimplementedDocumentPlugin } @@ -63,7 +61,9 @@ type MongoDocService struct { func (s *MongoDocService) Get(key *document.Key) (*document.Document, error) { newErr := errors.ErrorsWithScope( "MongoDocService.Get", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -77,7 +77,7 @@ func (s *MongoDocService) Get(key *document.Key) (*document.Document, error) { col := s.getCollection(key) docRef := bson.M{primaryKeyAttr: key.Id} - var value map[string]interface{}; + var value map[string]interface{} opts := options.FindOne() @@ -85,7 +85,7 @@ func (s *MongoDocService) Get(key *document.Key) (*document.Document, error) { opts.SetProjection(bson.M{primaryKeyAttr: 0, parentKeyAttr: 0, childrenAttr: 0}) err := col.FindOne(s.context, docRef, opts).Decode(&value) - + if err != nil { var code = codes.Internal if err == mongo.ErrNoDocuments { @@ -112,7 +112,9 @@ func (s *MongoDocService) Get(key *document.Key) (*document.Document, error) { func (s *MongoDocService) Set(key *document.Key, value map[string]interface{}) error { newErr := errors.ErrorsWithScope( "MongoDocService.Set", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -131,20 +133,18 @@ func (s *MongoDocService) Set(key *document.Key, value map[string]interface{}) e ) } - - coll := s.getCollection(key) value = mapKeys(key, value) - + opts := options.Update().SetUpsert(true) - + filter := bson.M{primaryKeyAttr: key.Id} update := bson.D{{"$set", value}} - - _, err := coll.UpdateOne(s.context, filter, update, opts); - + + _, err := coll.UpdateOne(s.context, filter, update, opts) + if err != nil { return newErr( codes.Internal, @@ -156,7 +156,7 @@ func (s *MongoDocService) Set(key *document.Key, value map[string]interface{}) e // add references if key.Collection.Parent != nil { err := s.updateChildReferences(key, coll.Name(), "$addToSet") - + if err != nil { return newErr( codes.Internal, @@ -172,7 +172,9 @@ func (s *MongoDocService) Set(key *document.Key, value map[string]interface{}) e func (s *MongoDocService) Delete(key *document.Key) error { newErr := errors.ErrorsWithScope( "MongoDocService.Delete", - fmt.Sprintf("key=%v", key), + map[string]interface{}{ + "key": key, + }, ) if err := document.ValidateKey(key); err != nil { @@ -187,8 +189,8 @@ func (s *MongoDocService) Delete(key *document.Key) error { filter := bson.M{primaryKeyAttr: key.Id} - opts := options.FindOneAndDelete().SetProjection(bson.M{ childrenAttr: 1, primaryKeyAttr: 0 }) - + opts := options.FindOneAndDelete().SetProjection(bson.M{childrenAttr: 1, primaryKeyAttr: 0}) + var deletedDocument map[string]interface{} // Delete document @@ -222,7 +224,7 @@ func (s *MongoDocService) Delete(key *document.Key) error { // clean references if none left if key.Collection.Parent != nil { err := s.updateChildReferences(key, coll.Name(), "$pull") - + if err != nil { return newErr( codes.Internal, @@ -231,14 +233,16 @@ func (s *MongoDocService) Delete(key *document.Key) error { ) } } - - return nil; + + return nil } func (s *MongoDocService) Query(collection *document.Collection, expressions []document.QueryExpression, limit int, pagingToken map[string]string) (*document.QueryResult, error) { newErr := errors.ErrorsWithScope( "MongoDocService.Query", - fmt.Sprintf("collection=%v", collection), + map[string]interface{}{ + "collection": collection, + }, ) if err := document.ValidateQueryCollection(collection); err != nil { @@ -266,7 +270,7 @@ func (s *MongoDocService) Query(collection *document.Collection, expressions []d opts := options.Find() opts.SetProjection(bson.M{childrenAttr: 0}) - + if limit > 0 { opts.SetLimit(int64(limit)) @@ -278,14 +282,12 @@ func (s *MongoDocService) Query(collection *document.Collection, expressions []d for _, v := range strings.Split(tokens, "|") { vals = append(vals, v) } - + query[primaryKeyAttr] = bson.D{{"$gt", vals[len(vals)-1]}} } } } - - if collection.Parent != nil && collection.Parent.Id != "" { query[parentKeyAttr] = collection.Parent.Id } @@ -295,12 +297,12 @@ func (s *MongoDocService) Query(collection *document.Collection, expressions []d if exp.Operator == "startsWith" { expVal := fmt.Sprintf("%v", exp.Value) endRangeValue := document.GetEndRangeValue(expVal) - + startsWith := bson.D{ {s.getOperator(">="), expVal}, {s.getOperator("<"), endRangeValue}, } - + query[expOperand] = startsWith } else { @@ -314,7 +316,7 @@ func (s *MongoDocService) Query(collection *document.Collection, expressions []d orderByAttrib = expOperand } } - + queryResult := &document.QueryResult{ Documents: make([]document.Document, 0), } @@ -331,7 +333,7 @@ func (s *MongoDocService) Query(collection *document.Collection, expressions []d defer cursor.Close(s.context) for cursor.Next(s.context) { - var docSnap map[string]interface{}; + var docSnap map[string]interface{} err := cursor.Decode(&docSnap) @@ -352,7 +354,7 @@ func (s *MongoDocService) Query(collection *document.Collection, expressions []d Content: docSnap, Key: &document.Key{ Collection: collection, - Id: id, + Id: id, }, } @@ -369,7 +371,7 @@ func (s *MongoDocService) Query(collection *document.Collection, expressions []d delete(docSnap, parentKeyAttr) } - + queryResult.Documents = append(queryResult.Documents, sdkDoc) // If query limit configured determine continue tokens @@ -396,7 +398,6 @@ func New() (document.DocumentService, error) { return nil, fmt.Errorf("MongoDB missing environment variable: %v", mongoDBConnectionStringEnvVarName) } - database := utils.GetEnv(mongoDBDatabaseEnvVarName, "") if database == "" { @@ -415,7 +416,7 @@ func New() (document.DocumentService, error) { if clientError != nil { return nil, fmt.Errorf("mongodb error creating client: %v", clientError) } - + connectError := client.Connect(ctx) if connectError != nil { @@ -426,7 +427,7 @@ func New() (document.DocumentService, error) { return &MongoDocService{ client: client, - db: db, + db: db, context: context.Background(), }, nil } @@ -436,7 +437,7 @@ func NewWithClient(client *mongo.Client, database string, ctx context.Context) d return &MongoDocService{ client: client, - db: db, + db: db, context: ctx, } } @@ -449,7 +450,7 @@ func mapKeys(key *document.Key, source map[string]interface{}) map[string]interf newMap[key] = value } - parentKey := key.Collection.Parent + parentKey := key.Collection.Parent newMap[primaryKeyAttr] = key.Id @@ -463,11 +464,11 @@ func mapKeys(key *document.Key, source map[string]interface{}) map[string]interf func (s *MongoDocService) updateChildReferences(key *document.Key, subCollectionName string, action string) error { parentColl := s.getCollection(key.Collection.Parent) filter := bson.M{primaryKeyAttr: key.Collection.Parent.Id} - referenceMeta := bson.M{ childrenAttr: subCollectionName } + referenceMeta := bson.M{childrenAttr: subCollectionName} update := bson.D{{action, referenceMeta}} opts := options.Update().SetUpsert(true) - _, err := parentColl.UpdateOne(s.context, filter, update, opts); + _, err := parentColl.UpdateOne(s.context, filter, update, opts) if err != nil { return err @@ -476,7 +477,7 @@ func (s *MongoDocService) updateChildReferences(key *document.Key, subCollection return nil } -func (s *MongoDocService) getCollection(key *document.Key) *mongo.Collection { +func (s *MongoDocService) getCollection(key *document.Key) *mongo.Collection { collectionNames := []string{} parentKey := key.Collection.Parent @@ -492,4 +493,4 @@ func (s *MongoDocService) getCollection(key *document.Key) *mongo.Collection { func (s *MongoDocService) getOperator(operator string) string { return mongoOperatorMap[operator] -} \ No newline at end of file +} diff --git a/pkg/plugins/document/plugin.go b/pkg/plugins/document/plugin.go index 00025d38a..3aa00888e 100644 --- a/pkg/plugins/document/plugin.go +++ b/pkg/plugins/document/plugin.go @@ -23,17 +23,13 @@ import "fmt" const MaxSubCollectionDepth int = 1 type Collection struct { - Name string - Parent *Key + Name string `log:"Name"` + Parent *Key `log:"Parent"` } type Key struct { - Collection *Collection - Id string -} - -func (k *Key) String() string { - return fmt.Sprintf("Key{Collection: %v Id: %v}\n", k.Collection, k.Id) + Collection *Collection `log:"Collection"` + Id string `log:"Id"` } type Document struct { @@ -41,10 +37,6 @@ type Document struct { Content map[string]interface{} } -func (d *Document) String() string { - return fmt.Sprintf("Document{Content: %v}\n", d.Content) -} - type QueryExpression struct { Operand string Operator string diff --git a/pkg/plugins/errors/plugin_error.go b/pkg/plugins/errors/plugin_error.go index dfb55cfe1..5cb5ace42 100644 --- a/pkg/plugins/errors/plugin_error.go +++ b/pkg/plugins/errors/plugin_error.go @@ -21,59 +21,44 @@ import ( ) type PluginError struct { - code codes.Code - msg string - cause error + Code codes.Code + Msg string + Cause error + Plugin string + Args map[string]interface{} } func (p *PluginError) Unwrap() error { - return p.cause + return p.Cause } func (p *PluginError) Error() string { - if p.cause != nil { + if p.Cause != nil { // If the wrapped error is an ApiError than these should unwrap - return fmt.Sprintf("%s: \n %s", p.msg, p.cause.Error()) + return fmt.Sprintf("%s: \n %s", p.Msg, p.Cause.Error()) } - return fmt.Sprintf("%s", p.msg) + return fmt.Sprintf("%s", p.Msg) } // Code - returns a nitric api error code from an error or Unknown if the error was not a nitric api error func Code(e error) codes.Code { if pe, ok := e.(*PluginError); ok { - return pe.code + return pe.Code } return codes.Unknown } -// New - Creates a new nitric API error -func new(c codes.Code, msg string) error { - return &PluginError{ - code: c, - msg: msg, - } -} - -// NewWithCause - Creates a new nitric API error with the given error as it's cause -func newWithCause(c codes.Code, msg string, cause error) error { - return &PluginError{ - code: c, - msg: msg, - cause: cause, - } -} - // ErrorsWithScope - Returns a new reusable error factory with the given scope -func ErrorsWithScope(s string, ctx ...interface{}) func(c codes.Code, msg string, cause error) error { - return func(c codes.Code, msg string, cause error) error { - sMsg := fmt.Sprintf("%s(%v): %s", s, ctx, msg) - - if cause == nil { - return new(c, sMsg) +func ErrorsWithScope(scope string, args map[string]interface{}) func(c codes.Code, msg string, cause error) error { + return func(code codes.Code, msg string, cause error) error { + return &PluginError{ + Code: code, + Msg: msg, + Cause: cause, + Plugin: scope, + Args: args, } - - return newWithCause(c, sMsg, cause) } } diff --git a/pkg/plugins/events/dev/eventing.go b/pkg/plugins/events/dev/eventing.go index d80c662fb..d0c36dfb1 100644 --- a/pkg/plugins/events/dev/eventing.go +++ b/pkg/plugins/events/dev/eventing.go @@ -45,7 +45,10 @@ type LocalHttpeventsClient interface { func (s *LocalEventService) Publish(topic string, event *events.NitricEvent) error { newErr := errors.ErrorsWithScope( "LocalEventService.Publish", - fmt.Sprintf("topic=%s", topic), + map[string]interface{}{ + "topic": topic, + "event": event, + }, ) requestId := event.ID @@ -96,7 +99,7 @@ func (s *LocalEventService) Publish(topic string, event *events.NitricEvent) err } else { return newErr( codes.NotFound, - fmt.Sprintf("unable to find subscriber for topic"), + "unable to find subscriber for topic", nil, ) } diff --git a/pkg/plugins/events/event.go b/pkg/plugins/events/event.go index 33656a7f9..609c53ca8 100644 --- a/pkg/plugins/events/event.go +++ b/pkg/plugins/events/event.go @@ -15,7 +15,7 @@ package events // NitricEvent - An event for asynchronous processing and reactive programming type NitricEvent struct { - ID string `json:"id,omitempty"` - PayloadType string `json:"payloadType,omitempty"` + ID string `json:"id,omitempty" log:"ID"` + PayloadType string `json:"payloadType,omitempty" log:"PayloadType"` Payload map[string]interface{} `json:"payload,omitempty"` } diff --git a/pkg/plugins/events/pubsub/pubsub.go b/pkg/plugins/events/pubsub/pubsub.go index 2eddae8f7..5b828fb21 100644 --- a/pkg/plugins/events/pubsub/pubsub.go +++ b/pkg/plugins/events/pubsub/pubsub.go @@ -35,7 +35,7 @@ type PubsubEventService struct { } func (s *PubsubEventService) ListTopics() ([]string, error) { - newErr := errors.ErrorsWithScope("PubsubEventService.ListTopics") + newErr := errors.ErrorsWithScope("PubsubEventService.ListTopics", nil) iter := s.client.Topics(context.TODO()) var topics []string @@ -57,7 +57,10 @@ func (s *PubsubEventService) ListTopics() ([]string, error) { func (s *PubsubEventService) Publish(topic string, event *events.NitricEvent) error { newErr := errors.ErrorsWithScope( "PubsubEventService.Publish", - fmt.Sprintf("topic=%s", topic), + map[string]interface{}{ + "topic": topic, + "event": event, + }, ) ctx := context.TODO() diff --git a/pkg/plugins/events/sns/sns.go b/pkg/plugins/events/sns/sns.go index febbc706b..f731c9dda 100644 --- a/pkg/plugins/events/sns/sns.go +++ b/pkg/plugins/events/sns/sns.go @@ -56,7 +56,10 @@ func (s *SnsEventService) getTopicArnFromName(name *string) (*string, error) { func (s *SnsEventService) Publish(topic string, event *events.NitricEvent) error { newErr := errors.ErrorsWithScope( "SnsEventService.Publish", - fmt.Sprintf("topic=%s", topic), + map[string]interface{}{ + "topic": topic, + "event": event, + }, ) data, err := json.Marshal(event) @@ -103,7 +106,7 @@ func (s *SnsEventService) Publish(topic string, event *events.NitricEvent) error } func (s *SnsEventService) ListTopics() ([]string, error) { - newErr := errors.ErrorsWithScope("SnsEventService.ListTopics") + newErr := errors.ErrorsWithScope("SnsEventService.ListTopics", nil) topicsOutput, err := s.client.ListTopics(&sns.ListTopicsInput{}) diff --git a/pkg/plugins/queue/dev/queue.go b/pkg/plugins/queue/dev/queue.go index e338417c7..c9e66b6c0 100644 --- a/pkg/plugins/queue/dev/queue.go +++ b/pkg/plugins/queue/dev/queue.go @@ -47,7 +47,10 @@ type Item struct { func (s *DevQueueService) Send(queue string, task queue.NitricTask) error { newErr := errors.ErrorsWithScope( "DevQueueService.Send", - fmt.Sprintf("queue=%s", queue), + map[string]interface{}{ + "queue": queue, + "task": task, + }, ) if queue == "" { @@ -96,7 +99,10 @@ func (s *DevQueueService) Send(queue string, task queue.NitricTask) error { func (s *DevQueueService) SendBatch(q string, tasks []queue.NitricTask) (*queue.SendBatchResponse, error) { newErr := errors.ErrorsWithScope( "DevQueueService.SendBatch", - fmt.Sprintf("queue=%s", q), + map[string]interface{}{ + "queue": q, + "tasks.len": len(tasks), + }, ) if q == "" { @@ -156,7 +162,9 @@ func (s *DevQueueService) SendBatch(q string, tasks []queue.NitricTask) (*queue. func (s *DevQueueService) Receive(options queue.ReceiveOptions) ([]queue.NitricTask, error) { newErr := errors.ErrorsWithScope( "DevQueueService.Receive", - fmt.Sprintf("options=%v", options), + map[string]interface{}{ + "options": options, + }, ) if options.QueueName == "" { @@ -179,6 +187,13 @@ func (s *DevQueueService) Receive(options queue.ReceiveOptions) ([]queue.NitricT var items []Item err = db.All(&items, storm.Limit(int(*options.Depth))) + if err != nil { + return nil, newErr( + codes.Internal, + "error reading tasks", + err, + ) + } poppedTasks := make([]queue.NitricTask, 0) for _, item := range items { @@ -211,7 +226,10 @@ func (s *DevQueueService) Receive(options queue.ReceiveOptions) ([]queue.NitricT func (s *DevQueueService) Complete(queue string, leaseId string) error { newErr := errors.ErrorsWithScope( "DevQueueService.Complete", - fmt.Sprintf("queue=%s", queue), + map[string]interface{}{ + "queue": queue, + "leaseId": leaseId, + }, ) if queue == "" { diff --git a/pkg/plugins/queue/plugin.go b/pkg/plugins/queue/plugin.go index 8ee15bf39..b54f058a6 100644 --- a/pkg/plugins/queue/plugin.go +++ b/pkg/plugins/queue/plugin.go @@ -39,12 +39,12 @@ type ReceiveOptions struct { // Nitric name for the queue. // // queueName is a required field - QueueName string `type:"string" required:"true"` + QueueName string `type:"string" required:"true" log:"QueueName"` // Max depth of queue messages to receive from the queue. // // If nil or 0, defaults to depth 1. - Depth *uint32 `type:"int" required:"false"` + Depth *uint32 `type:"int" required:"false" log:"Depth"` } func (p *ReceiveOptions) Validate() error { diff --git a/pkg/plugins/queue/pubsub/pubsub.go b/pkg/plugins/queue/pubsub/pubsub.go index 81c9b37cd..65f56d684 100644 --- a/pkg/plugins/queue/pubsub/pubsub.go +++ b/pkg/plugins/queue/pubsub/pubsub.go @@ -49,7 +49,10 @@ func generateQueueSubscription(queue string) string { func (s *PubsubQueueService) Send(queue string, task queue.NitricTask) error { newErr := errors.ErrorsWithScope( "PubsubQueueService.Send", - fmt.Sprintf("queue=%s", queue), + map[string]interface{}{ + "queue": queue, + "task": task, + }, ) // We'll be using pubsub with pull subscribers to facilitate queue functionality ctx := context.TODO() @@ -58,7 +61,7 @@ func (s *PubsubQueueService) Send(queue string, task queue.NitricTask) error { if exists, err := topic.Exists(ctx); !exists || err != nil { return newErr( codes.NotFound, - fmt.Sprintf("queue not found"), + "queue not found", err, ) } @@ -91,7 +94,10 @@ func (s *PubsubQueueService) Send(queue string, task queue.NitricTask) error { func (s *PubsubQueueService) SendBatch(q string, tasks []queue.NitricTask) (*queue.SendBatchResponse, error) { newErr := errors.ErrorsWithScope( "PubsubQueueService.SendBatch", - fmt.Sprintf("queue=%s", q), + map[string]interface{}{ + "queue": q, + "tasks.len": len(tasks), + }, ) // We'll be using pubsub with pull subscribers to facilitate queue functionality @@ -177,7 +183,9 @@ func (s *PubsubQueueService) getQueueSubscription(q string) (ifaces_pubsub.Subsc func (s *PubsubQueueService) Receive(options queue.ReceiveOptions) ([]queue.NitricTask, error) { newErr := errors.ErrorsWithScope( "PubsubQueueService.Receive", - fmt.Sprintf("options=%v", options), + map[string]interface{}{ + "options": options, + }, ) if err := options.Validate(); err != nil { @@ -259,7 +267,10 @@ func (s *PubsubQueueService) Receive(options queue.ReceiveOptions) ([]queue.Nitr func (s *PubsubQueueService) Complete(q string, leaseId string) error { newErr := errors.ErrorsWithScope( "PubsubQueueService.Complete", - fmt.Sprintf("queue=%s", q), + map[string]interface{}{ + "queue": q, + "leaseId": leaseId, + }, ) ctx := context.Background() diff --git a/pkg/plugins/queue/sqs/sqs.go b/pkg/plugins/queue/sqs/sqs.go index 63b673e1a..fb8940013 100644 --- a/pkg/plugins/queue/sqs/sqs.go +++ b/pkg/plugins/queue/sqs/sqs.go @@ -56,7 +56,10 @@ func (s *SQSQueueService) getUrlForQueueName(queueName string) (*string, error) func (s *SQSQueueService) Send(queueName string, task queue.NitricTask) error { newErr := errors.ErrorsWithScope( "SQSQueueService.Send", - fmt.Sprintf("queue=%s", queueName), + map[string]interface{}{ + "queue": queueName, + "task": task, + }, ) tasks := []queue.NitricTask{task} @@ -73,7 +76,10 @@ func (s *SQSQueueService) Send(queueName string, task queue.NitricTask) error { func (s *SQSQueueService) SendBatch(queueName string, tasks []queue.NitricTask) (*queue.SendBatchResponse, error) { newErr := errors.ErrorsWithScope( "SQSQueueService.SendBatch", - fmt.Sprintf("queue=%s", queueName), + map[string]interface{}{ + "queue": queueName, + "tasks.len": len(tasks), + }, ) if url, err := s.getUrlForQueueName(queueName); err == nil { @@ -137,7 +143,9 @@ func (s *SQSQueueService) SendBatch(queueName string, tasks []queue.NitricTask) func (s *SQSQueueService) Receive(options queue.ReceiveOptions) ([]queue.NitricTask, error) { newErr := errors.ErrorsWithScope( "SQSQueueService.Receive", - fmt.Sprintf("options=%v", options), + map[string]interface{}{ + "options": options, + }, ) if err := options.Validate(); err != nil { @@ -205,7 +213,10 @@ func (s *SQSQueueService) Receive(options queue.ReceiveOptions) ([]queue.NitricT func (s *SQSQueueService) Complete(q string, leaseId string) error { newErr := errors.ErrorsWithScope( "SQSQueueService.Complete", - fmt.Sprintf("queue=%s", q), + map[string]interface{}{ + "queue": q, + "leaseId": leaseId, + }, ) if url, err := s.getUrlForQueueName(q); err == nil { diff --git a/pkg/plugins/queue/task.go b/pkg/plugins/queue/task.go index bd1c53bb8..c27e44b70 100644 --- a/pkg/plugins/queue/task.go +++ b/pkg/plugins/queue/task.go @@ -22,8 +22,8 @@ type FailedTask struct { // NitricTask - A task for asynchronous processing type NitricTask struct { - ID string `json:"id,omitempty"` - LeaseID string `json:"leaseId,omitempty"` - PayloadType string `json:"payloadType,omitempty"` + ID string `json:"id,omitempty" log:"ID"` + LeaseID string `json:"leaseId,omitempty" log:"LeaseID"` + PayloadType string `json:"payloadType,omitempty" log:"PayLoadType"` Payload map[string]interface{} `json:"payload,omitempty"` } diff --git a/pkg/plugins/secret/dev/dev.go b/pkg/plugins/secret/dev/dev.go index cfb82ff98..754aa2cb0 100644 --- a/pkg/plugins/secret/dev/dev.go +++ b/pkg/plugins/secret/dev/dev.go @@ -42,7 +42,12 @@ func (s *DevSecretService) secretFileName(sec *secret.Secret, v string) string { } func (s *DevSecretService) Put(sec *secret.Secret, val []byte) (*secret.SecretPutResponse, error) { - newErr := errors.ErrorsWithScope("DevSecretService.Put") + newErr := errors.ErrorsWithScope( + "DevSecretService.Put", + map[string]interface{}{ + "secret": sec, + }, + ) if sec == nil { return nil, newErr(codes.InvalidArgument, "provide non-empty secret", nil) @@ -94,7 +99,12 @@ func (s *DevSecretService) Put(sec *secret.Secret, val []byte) (*secret.SecretPu } func (s *DevSecretService) Access(sv *secret.SecretVersion) (*secret.SecretAccessResponse, error) { - newErr := errors.ErrorsWithScope("DevSecretService.Access") + newErr := errors.ErrorsWithScope( + "DevSecretService.Access", + map[string]interface{}{ + "version": sv, + }, + ) if sv.Secret.Name == "" { return nil, newErr( diff --git a/pkg/plugins/secret/secret_manager/secret_manager.go b/pkg/plugins/secret/secret_manager/secret_manager.go index fe8738924..febe6c53b 100644 --- a/pkg/plugins/secret/secret_manager/secret_manager.go +++ b/pkg/plugins/secret/secret_manager/secret_manager.go @@ -135,7 +135,12 @@ func (s *secretManagerSecretService) ensureSecret(sec *secret.Secret) (*secretma // Put - Creates a new secret if one doesn't exist, or just adds a new secret version func (s *secretManagerSecretService) Put(sec *secret.Secret, val []byte) (*secret.SecretPutResponse, error) { - newErr := errors.ErrorsWithScope("SecretManagerSecretService.Put") + newErr := errors.ErrorsWithScope( + "SecretManagerSecretService.Put", + map[string]interface{}{ + "secret": sec, + }, + ) if err := validateNewSecret(sec, val); err != nil { return nil, newErr( @@ -186,7 +191,12 @@ func (s *secretManagerSecretService) Put(sec *secret.Secret, val []byte) (*secre // Get - Retrieves a secret given a name and a version func (s *secretManagerSecretService) Access(sv *secret.SecretVersion) (*secret.SecretAccessResponse, error) { - newErr := errors.ErrorsWithScope("SecretManagerSecretService.Access") + newErr := errors.ErrorsWithScope( + "SecretManagerSecretService.Access", + map[string]interface{}{ + "version": sv, + }, + ) fullName, err := s.buildSecretVersionName(sv) diff --git a/pkg/plugins/secret/secret_suite_test.go b/pkg/plugins/secret/secret_suite_test.go index d2c01c74f..fffd63491 100644 --- a/pkg/plugins/secret/secret_suite_test.go +++ b/pkg/plugins/secret/secret_suite_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package secret +package secret_test import ( "testing" diff --git a/pkg/plugins/secret/secret_test.go b/pkg/plugins/secret/secret_test.go index 510631e4b..7e93178a2 100644 --- a/pkg/plugins/secret/secret_test.go +++ b/pkg/plugins/secret/secret_test.go @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package secret +package secret_test import ( + "github.com/nitric-dev/membrane/pkg/plugins/secret" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Unimplemented Secret Plugin Tests", func() { - uisp := &UnimplementedSecretPlugin{} + uisp := &secret.UnimplementedSecretPlugin{} Context("Put", func() { When("Calling Put on UnimplementedSecretPlugin", func() { diff --git a/pkg/plugins/secret/secrets_manager/secrets_manager.go b/pkg/plugins/secret/secrets_manager/secrets_manager.go index 5745e74fd..bd45394e3 100644 --- a/pkg/plugins/secret/secrets_manager/secrets_manager.go +++ b/pkg/plugins/secret/secrets_manager/secrets_manager.go @@ -49,7 +49,12 @@ func (s *secretsManagerSecretService) validateNewSecret(sec *secret.Secret, val } func (s *secretsManagerSecretService) Put(sec *secret.Secret, val []byte) (*secret.SecretPutResponse, error) { - newErr := errors.ErrorsWithScope("SecretsManagerSecretService.Put") + newErr := errors.ErrorsWithScope( + "SecretManagerSecretService.Put", + map[string]interface{}{ + "secret": sec, + }, + ) if err := s.validateNewSecret(sec, val); err != nil { return nil, newErr( @@ -136,7 +141,12 @@ func (s *secretsManagerSecretService) Put(sec *secret.Secret, val []byte) (*secr } func (s *secretsManagerSecretService) Access(sv *secret.SecretVersion) (*secret.SecretAccessResponse, error) { - newErr := errors.ErrorsWithScope("SecretsManagerSecretService.Access") + newErr := errors.ErrorsWithScope( + "SecretManagerSecretService.Access", + map[string]interface{}{ + "version": sv, + }, + ) if len(sv.Secret.Name) == 0 { return nil, newErr( diff --git a/pkg/plugins/secret/types.go b/pkg/plugins/secret/types.go index ac3f86c13..1d7814e63 100644 --- a/pkg/plugins/secret/types.go +++ b/pkg/plugins/secret/types.go @@ -16,16 +16,16 @@ package secret // Secret - Represents a container for secret versions type Secret struct { - Name string + Name string `log:"Name"` } // SecretVersion - A version of a secret type SecretVersion struct { - Secret *Secret + Secret *Secret `log:"Secret"` // Version - the specific secret version this represents // Specifying "latest" will always retrieve the latest version of the secret - Version string + Version string `log:"Version"` } // SecretAccessResponse - Return value for a secret access request diff --git a/pkg/plugins/storage/boltdb/storage.go b/pkg/plugins/storage/boltdb/storage.go index 7b4b4d63f..34bc22f70 100644 --- a/pkg/plugins/storage/boltdb/storage.go +++ b/pkg/plugins/storage/boltdb/storage.go @@ -15,7 +15,6 @@ package boltdb_storage_service import ( - "fmt" "os" "strings" "time" @@ -45,8 +44,11 @@ type Object struct { func (s *BoltStorageService) Write(bucket string, key string, object []byte) error { newErr := errors.ErrorsWithScope( "BoltStorageService.Write", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + "object.len": len(object), + }, ) if bucket == "" { @@ -109,8 +111,10 @@ func (s *BoltStorageService) Write(bucket string, key string, object []byte) err func (s *BoltStorageService) Read(bucket string, key string) ([]byte, error) { newErr := errors.ErrorsWithScope( "BoltStorageService.Read", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + }, ) if bucket == "" { @@ -156,8 +160,10 @@ func (s *BoltStorageService) Read(bucket string, key string) ([]byte, error) { func (s *BoltStorageService) Delete(bucket string, key string) error { newErr := errors.ErrorsWithScope( "BoltStorageService.Delete", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + }, ) if bucket == "" { diff --git a/pkg/plugins/storage/s3/s3.go b/pkg/plugins/storage/s3/s3.go index ca84dff0e..f98b1abbc 100644 --- a/pkg/plugins/storage/s3/s3.go +++ b/pkg/plugins/storage/s3/s3.go @@ -83,8 +83,10 @@ func (s *S3StorageService) getBucketByName(bucket string) (*s3.Bucket, error) { func (s *S3StorageService) Read(bucket string, key string) ([]byte, error) { newErr := errors.ErrorsWithScope( "S3StorageService.Read", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + }, ) if b, err := s.getBucketByName(bucket); err == nil { @@ -117,8 +119,11 @@ func (s *S3StorageService) Read(bucket string, key string) ([]byte, error) { func (s *S3StorageService) Write(bucket string, key string, object []byte) error { newErr := errors.ErrorsWithScope( "S3StorageService.Write", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + "object.len": len(object), + }, ) if b, err := s.getBucketByName(bucket); err == nil { @@ -151,8 +156,10 @@ func (s *S3StorageService) Write(bucket string, key string, object []byte) error func (s *S3StorageService) Delete(bucket string, key string) error { newErr := errors.ErrorsWithScope( "S3StorageService.Delete", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + }, ) if b, err := s.getBucketByName(bucket); err == nil { diff --git a/pkg/plugins/storage/storage/storage.go b/pkg/plugins/storage/storage/storage.go index 986a7792e..7390b3420 100644 --- a/pkg/plugins/storage/storage/storage.go +++ b/pkg/plugins/storage/storage/storage.go @@ -61,8 +61,10 @@ func (s *StorageStorageService) getBucketByName(bucket string) (ifaces_gcloud_st func (s *StorageStorageService) Read(bucket string, key string) ([]byte, error) { newErr := errors.ErrorsWithScope( "StorageStorageService.Read", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + }, ) bucketHandle, err := s.getBucketByName(bucket) @@ -102,8 +104,11 @@ func (s *StorageStorageService) Read(bucket string, key string) ([]byte, error) func (s *StorageStorageService) Write(bucket string, key string, object []byte) error { newErr := errors.ErrorsWithScope( "StorageStorageService.Write", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + "object.len": len(object), + }, ) bucketHandle, err := s.getBucketByName(bucket) @@ -143,8 +148,10 @@ func (s *StorageStorageService) Write(bucket string, key string, object []byte) func (s *StorageStorageService) Delete(bucket string, key string) error { newErr := errors.ErrorsWithScope( "StorageStorageService.Delete", - fmt.Sprintf("bucket=%s", bucket), - fmt.Sprintf("key=%s", key), + map[string]interface{}{ + "bucket": bucket, + "key": key, + }, ) bucketHandle, err := s.getBucketByName(bucket)