From c5fae0e751214415f02a8b87aea4ce77515d7ea4 Mon Sep 17 00:00:00 2001 From: Alex Snast Date: Wed, 28 Oct 2020 14:25:09 +0200 Subject: [PATCH] entc/gen: add hook.FixedError helper (#895) --- entc/gen/internal/bindata.go | 4 ++-- entc/gen/template/hook.tmpl | 16 +++++++++++----- entc/integration/config/ent/hook/hook.go | 15 ++++++++++----- entc/integration/customid/ent/hook/hook.go | 15 ++++++++++----- entc/integration/ent/hook/hook.go | 15 ++++++++++----- entc/integration/gremlin/ent/hook/hook.go | 15 ++++++++++----- entc/integration/hooks/ent/hook/hook.go | 15 ++++++++++----- entc/integration/idtype/ent/hook/hook.go | 15 ++++++++++----- entc/integration/json/ent/hook/hook.go | 15 ++++++++++----- entc/integration/migrate/entv1/hook/hook.go | 15 ++++++++++----- entc/integration/migrate/entv2/hook/hook.go | 15 ++++++++++----- entc/integration/privacy/ent/hook/hook.go | 15 ++++++++++----- entc/integration/template/ent/hook/hook.go | 15 ++++++++++----- examples/edgeindex/ent/hook/hook.go | 15 ++++++++++----- examples/entcpkg/ent/hook/hook.go | 15 ++++++++++----- examples/m2m2types/ent/hook/hook.go | 15 ++++++++++----- examples/m2mbidi/ent/hook/hook.go | 15 ++++++++++----- examples/m2mrecur/ent/hook/hook.go | 15 ++++++++++----- examples/o2m2types/ent/hook/hook.go | 15 ++++++++++----- examples/o2mrecur/ent/hook/hook.go | 15 ++++++++++----- examples/o2o2types/ent/hook/hook.go | 15 ++++++++++----- examples/o2obidi/ent/hook/hook.go | 15 ++++++++++----- examples/o2orecur/ent/hook/hook.go | 15 ++++++++++----- examples/privacyadmin/ent/hook/hook.go | 15 ++++++++++----- examples/privacytenant/ent/hook/hook.go | 15 ++++++++++----- examples/start/ent/hook/hook.go | 15 ++++++++++----- examples/traversal/ent/hook/hook.go | 15 ++++++++++----- 27 files changed, 263 insertions(+), 132 deletions(-) diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index fd508145e..03e11c07c 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -970,7 +970,7 @@ func templateHeaderTmpl() (*asset, error) { return a, nil } -var _templateHookTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x58\xdd\x8f\xdb\xb8\x11\x7f\xb6\xff\x8a\x89\xe0\x00\x52\xaa\xa5\x73\xf7\xd6\x06\x29\xb0\xf0\x25\xc8\x02\xd7\x75\x71\xcd\xf5\xe5\x70\xc8\x31\xd2\xc8\x66\x2d\x93\x02\x49\xef\x07\x1c\xfd\xef\xc5\x0c\x45\x49\xb6\x76\xf7\xf6\xd2\x14\xf7\xb2\x6b\xcf\x0c\xe7\xe3\x37\x1f\x1c\xfa\x78\x5c\xbe\x9a\xaf\x4c\x73\x6f\xd5\x66\xeb\xe1\xfb\xd7\xdf\xfd\xf5\xa2\xb1\xe8\x50\x7b\x78\x2f\x0b\xfc\x6c\xcc\x0e\xae\x74\x21\xe0\xb2\xae\x81\x85\x1c\x10\xdf\xde\x60\x29\xe6\x1f\xb7\xca\x81\x33\x07\x5b\x20\x14\xa6\x44\x50\x0e\x6a\x55\xa0\x76\x58\xc2\x41\x97\x68\xc1\x6f\x11\x2e\x1b\x59\x6c\x11\xbe\x17\xaf\x23\x17\x2a\x73\xd0\xe5\x5c\x69\xe6\xff\x78\xb5\x7a\x77\xfd\xaf\x77\x50\xa9\x1a\xa1\xa3\x59\x63\x3c\x94\xca\x62\xe1\x8d\xbd\x07\x53\x81\x1f\x19\xf3\x16\x51\xcc\x5f\x2d\xdb\x76\x3e\x3f\x1e\xa1\xc4\x4a\x69\x84\x64\x6b\xcc\x2e\x81\x8e\x78\xab\xfc\x16\xf0\xce\xa3\x2e\x61\x01\xc9\x3f\x65\xb1\x93\x1b\x4c\x46\x52\xb3\xe3\x11\x3c\xee\x9b\x5a\x7a\x3a\x8c\xb2\x44\x9b\x80\x20\xd6\xf1\x08\x74\x8e\x54\xa9\x7d\x63\xac\x87\xe4\x78\x84\x85\x58\x19\x5d\xa9\x8d\xe8\x94\x41\xdb\x26\x6c\x6b\xd1\xec\x36\xf0\xb7\xb7\xf0\x59\x3a\x7c\x48\x8a\x85\xac\xd4\x1b\x84\x85\x26\xc1\x85\xb8\x36\x25\xba\xe8\xc5\x42\xcb\x3d\x12\xbd\xb1\x4a\x7b\x58\x68\x71\x4d\x84\xe4\xfd\x41\x17\xbd\xab\x0b\x7f\xdf\x0c\x42\x15\x24\xaf\x5e\x3a\xf1\xd2\x25\xc1\xfa\x42\x8b\x7f\x1c\xbc\xf4\xca\x68\x3e\x4b\x46\x67\xcb\x25\x7c\xdc\x22\xf4\x16\xda\x16\x58\x89\x72\x20\x35\xc8\x52\x36\x9e\x72\x64\x40\xd6\xb5\xb9\x65\xe0\x0f\x0e\x09\x6d\x63\x4b\xa5\xa5\xbd\x67\x1d\xd5\x41\x17\xa4\x18\xa4\x0b\xba\x44\x67\x02\xf6\x64\xd2\x58\x31\x9f\xb1\xde\xb1\x21\x3a\x94\x16\x46\x7b\xbc\xf3\x84\x08\xfd\xcf\xa1\x8f\xa3\x6d\x33\x48\x23\x74\x6d\x2b\xfe\x2d\xeb\x03\xe6\x80\xd6\x1a\x9b\x05\xd7\x39\x1e\x84\x42\xd6\xb5\x83\x2a\x2d\xfc\x5d\x0e\xfb\x4c\xcc\x67\xa4\x1a\xd2\x6a\x6c\x2e\xeb\xa4\x49\x0a\x26\x56\xf7\x30\xb2\x14\x61\x7a\xc2\x3e\x1c\xe7\xb3\xd9\xfe\x26\x07\xb3\x23\xc0\xf7\x22\x1d\xfb\x3d\x9f\xcd\x54\x05\x2f\xcc\x8e\xc5\x66\x16\xfd\xc1\x6a\xd0\xaa\xce\xa1\xda\x7b\xf1\x8e\x54\x54\x69\x72\xd0\x78\xd7\x60\xe1\xb1\x0c\x30\x11\x80\xac\xe2\xe5\x47\x01\x81\x35\x86\x23\xa1\xe0\xe6\xb3\x59\x3b\xef\x55\xc6\x98\x6f\xb2\xf9\xec\xa4\x26\x97\x4b\x58\x19\x5d\x2a\xd6\x49\xc9\x04\x2a\x6a\x8a\xbb\xa3\xc5\x8c\x89\x39\x6b\x5f\x9d\x30\x1e\xce\xca\x04\x9d\xcf\xc6\xd4\x6c\xea\x52\x97\xb0\xb1\xe6\xd0\xb8\xc1\x82\x0b\xfd\xc5\xed\x7d\xfd\x03\x98\x06\x6d\x28\x04\xce\xcd\xa5\x2e\xd3\x4a\x59\xe7\x73\x70\x48\x67\x06\x0f\x72\x9a\x1f\x1e\x84\x10\x3d\x29\x1b\xf9\x77\x9c\xf7\xc1\xb3\xa7\x7f\x20\x9b\xe4\x2f\x67\x84\x92\xc3\xd6\x63\xc9\xc0\x97\x2f\xf0\x22\x38\xd2\x93\xc6\xa9\xab\x64\xed\xb0\x83\xbe\x32\x16\x3e\xe5\x1c\x28\xa5\x3e\x34\x2d\xbb\xcc\x27\x48\xf7\x54\xcf\xb9\x22\xd6\x34\x4a\xa4\xb7\x07\xa4\x14\x86\xd4\xad\xed\x53\x70\xae\x7f\x3a\x47\x73\x6d\xff\x5c\x30\x27\x58\x3e\x01\x65\x88\xf4\x99\x48\x3e\x0e\x64\xa7\xe6\x1c\xc7\x0e\xdf\x08\xe4\xb5\xf1\xa0\x71\x23\x3d\x52\x0b\x6c\xd4\x0d\xea\x01\xd2\x0e\xbc\x6b\xe3\xd3\x53\xd0\xbe\x35\x42\x9d\x82\x93\xb2\x18\x7c\xfc\x20\xdd\xba\x09\x3d\x3a\xb4\xa7\x47\xe7\x95\xde\x0c\x73\x21\x64\x7c\xf0\x9a\x4f\xa5\xa6\x19\x9b\x5e\x37\x4f\x78\xfe\xe9\xab\xfd\xde\x8b\x75\x93\x66\xe2\xca\xa5\xa6\x89\x7e\xd3\x41\xf2\xd6\x51\xe2\x4a\x55\x78\x48\x3e\x48\xf7\x5e\x61\x5d\xba\x04\x12\xfe\x90\x30\xed\xb2\x2c\xb1\xec\x19\xc3\xb7\xc0\x5d\xd5\x28\xed\x88\xcf\x1f\x3a\x62\x02\x17\x7c\xd1\x5e\xc4\x8b\x31\x16\xca\x0e\xef\x5d\x34\x1f\xaf\xbe\x3d\xfa\xad\x61\xee\x06\x7d\x64\x86\x13\xa4\x85\x6e\x8b\xe8\x33\xdd\x3d\x67\x70\xdf\xc8\x5a\x95\x92\x11\xff\x4d\x8c\xd4\xb5\xed\x6f\x40\x33\x91\xdd\x8b\xf7\xca\x48\x4f\xca\x1c\x70\xde\x2a\xbd\xc9\x3b\x39\xea\xb6\x40\x39\x4b\xc7\xff\x9a\x0f\xea\x88\xe3\x11\x54\x05\x1a\x7b\x17\xcf\x20\x6b\xdb\x4f\x3c\xad\xc3\x45\x80\x77\xca\x79\x17\x6e\xa8\x93\xb0\x82\xe3\xd9\x1b\x78\xd1\x89\x3c\x3e\xa5\x62\x9b\x86\x50\xfb\x3e\xed\x62\x0d\xe7\xfe\xef\x8e\x4d\x3c\x0b\xae\xb5\x0f\x0e\x96\x50\x34\xa3\xab\xf0\xaa\x02\xbc\xc3\xe2\x40\x63\x80\x26\x68\x18\x04\x7c\x23\x86\x25\x74\x34\x13\x96\xcb\xf9\x72\x39\x23\x9e\xb8\xaa\xd2\x95\xd9\x37\x07\x8f\x97\x37\x68\xe5\x06\x73\xbe\xb7\xfa\x42\x4f\x85\x10\x59\x0e\xa7\x45\xce\xc4\x2c\x23\x3d\x5c\x2d\x57\x55\xba\xdd\x8d\x13\xfb\xc1\x98\x5d\x37\xf4\x46\x13\xe7\x4c\xe0\xbc\x7b\x35\xde\xf9\x49\x75\xf0\x1e\x32\xa1\x8d\x2b\xed\x9c\x8b\xb4\x2f\xa6\x7f\x78\x92\x3d\xbd\x06\x3d\x3d\xa8\xb7\x3b\x76\x3e\x13\xc3\xfa\xd5\xed\x31\x27\xd9\x23\x99\xa9\x48\x3b\x9a\x93\x6b\xfd\x68\x12\x8d\xae\xef\x81\xca\x74\xa0\x8f\xe6\xe5\x28\xa3\x6b\x9d\xfe\x68\x36\x27\xeb\xcc\x0f\x58\xa3\xc7\x2f\x23\xca\xca\xa2\xf4\x38\x64\x70\xad\x1f\xcc\xe0\x74\xf6\x3e\x9e\x43\x2e\x82\xbc\x1f\xda\x59\xd6\xc5\xf4\xb3\xae\xd1\x39\x70\x3b\xd5\x7c\x7d\x50\x41\xc9\x24\xb0\x9f\x9b\x52\x9e\x06\x16\x28\x6b\x3d\x8a\xad\x3b\xfb\x8d\xe2\xa3\xab\x74\x88\x31\x06\xf9\x13\xfe\x87\x36\xd9\x20\xda\xaf\xa2\x7e\x2b\x89\x46\x2c\x47\xaf\x8b\x21\x38\x17\x78\x7b\xe9\x8b\x2d\x98\x26\xc6\x1a\x76\xfa\x8f\x19\x90\x6d\x97\x66\xf0\xcb\xaf\x53\x87\x96\xcb\xbe\xa2\x26\xec\xc0\x9d\x05\x77\xd2\x27\x4b\x20\x20\x95\xe5\x7c\xa2\xa5\xbf\x6d\x0f\x59\x77\xfe\x59\xf0\x6c\xf9\x75\xc0\xfd\xf6\x4d\x9b\xf7\xf9\x97\xc7\xef\xb4\xee\x63\x4f\x93\x97\x6e\xc8\x07\x5d\x96\xda\xf8\xf0\x04\xc4\x92\x9e\x21\xbc\x11\x0c\x0d\x1a\xd5\x70\xa7\x50\xe5\xc4\xd4\xaf\xb6\x52\x69\x90\x9c\x62\xca\x7c\xad\x9c\xa7\xc7\x23\x55\x00\xbd\x30\x4b\xd2\x8d\x55\x85\x85\x57\x37\x58\xdf\x83\xda\xd3\xc6\xf3\xb9\x46\x11\x5a\xbe\x40\x28\xb8\x1d\xcb\x1c\x94\x87\x5b\x55\xd7\x20\xeb\x5b\x79\xef\x60\x6b\xea\x92\x7b\xc3\xd1\x03\xcf\xe1\x48\x71\xf7\x13\x01\x33\x8c\x2d\xd1\xc6\x57\x0e\xbb\xe3\xbc\x3d\x14\xbc\x63\x06\xe9\x49\xa1\xc4\xe5\x11\x6f\xc3\x81\xe0\x01\xf9\xaf\xf1\x16\x0a\xa6\x45\x5b\x71\x89\xec\x64\xd3\xa0\x52\x08\x71\xa6\x33\xeb\x8c\x0f\x3d\xc3\xdf\x8f\xb2\x69\x50\x97\xe9\xc4\x87\x54\xab\x3a\xcb\x3b\x1b\x42\x64\xfd\xb6\xc8\xcf\x38\x3a\x1a\x06\xc6\x14\xd1\xd8\x67\xc4\xad\x94\x96\x35\xf3\x3a\x3f\xd3\x22\xd8\x0d\x5d\x94\xfe\xee\xbd\xb3\x8f\x65\xf9\xfc\xea\xa5\x91\xa5\xa8\xec\x6b\xd4\x69\x21\xd8\xb1\x0c\x2e\xe0\xbb\x37\xa0\xe0\xef\x6f\xe1\xf5\x1b\x50\x17\x17\xa1\xfc\xa2\xfa\xb7\xd0\x09\xfe\xa2\x7e\x8d\x36\xcf\x9e\xba\x1d\x75\xb8\x0f\x2e\x19\xb9\xee\x07\x1c\x5e\xe7\x28\xb0\x1c\x64\x59\xd2\x1e\xc7\x05\xd0\x60\xa1\x2a\x85\x25\x43\x40\x87\x64\x87\x9a\x24\xd4\x34\xf6\xa5\xd2\xef\xd9\x55\x6d\x6e\x27\x58\x05\x53\xcf\xc9\xad\xc6\x5b\x1e\x4f\xbc\xd9\xc8\x1d\x4e\x13\x9b\xc3\xeb\xfc\x04\x9a\xbf\xd0\x97\xf0\x31\x1b\x29\x78\x0b\x5d\x69\x44\x4a\x1e\x31\xa2\x72\x78\x5a\x70\x24\x76\x52\x6c\x51\x22\x42\xf8\x2e\xfc\xf8\xf5\x3c\x08\x99\xf7\xf5\x18\x06\x5b\x69\xe8\x9e\x8e\x76\xde\x12\x85\xe8\x90\x66\xa9\x51\xb4\xe1\xc5\xd1\x6d\x74\xff\x0d\x00\x00\xff\xff\x6f\xf8\xfb\xdb\x94\x14\x00\x00") +var _templateHookTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x58\xdd\x8f\xdb\xb8\x11\x7f\xb6\xff\x8a\x89\xe0\x00\x52\xaa\xa5\x73\xf7\xd6\x06\x29\xb0\xf0\x25\xc8\x02\xd7\x75\x71\xcd\xf5\xe5\x70\xc8\x31\xe2\xc8\x66\x2d\x93\x02\x49\xef\x07\x1c\xfd\xef\xc5\x90\x94\x44\x5b\x89\x6f\x2f\x4d\x71\x2f\xbb\xf6\xcc\x70\x3e\x7e\xf3\xc1\xa1\x8f\xc7\xe5\x8b\xf9\x4a\xb7\x8f\x46\x6e\xb6\x0e\xbe\x7f\xf9\xdd\x5f\xaf\x5a\x83\x16\x95\x83\xb7\xbc\xc2\x8f\x5a\xef\xe0\x46\x55\x0c\xae\x9b\x06\xbc\x90\x05\xe2\x9b\x3b\x14\x6c\xfe\x7e\x2b\x2d\x58\x7d\x30\x15\x42\xa5\x05\x82\xb4\xd0\xc8\x0a\x95\x45\x01\x07\x25\xd0\x80\xdb\x22\x5c\xb7\xbc\xda\x22\x7c\xcf\x5e\xf6\x5c\xa8\xf5\x41\x89\xb9\x54\x9e\xff\xe3\xcd\xea\xcd\xed\xbf\xde\x40\x2d\x1b\x84\x48\x33\x5a\x3b\x10\xd2\x60\xe5\xb4\x79\x04\x5d\x83\x4b\x8c\x39\x83\xc8\xe6\x2f\x96\x5d\x37\x9f\x1f\x8f\x20\xb0\x96\x0a\x21\xdb\x6a\xbd\xcb\x20\x12\xef\xa5\xdb\x02\x3e\x38\x54\x02\x16\x90\xfd\x93\x57\x3b\xbe\xc1\x2c\x91\x9a\x1d\x8f\xe0\x70\xdf\x36\xdc\xd1\x61\xe4\x02\x4d\x06\x8c\x58\xc7\x23\xd0\x39\x52\x25\xf7\xad\x36\x0e\xb2\xe3\x11\x16\x6c\xa5\x55\x2d\x37\x2c\x2a\x83\xae\xcb\xbc\xad\x45\xbb\xdb\xc0\xdf\x5e\xc3\x47\x6e\xf1\x73\x52\x5e\xc8\x70\xb5\x41\x58\x28\x12\x5c\xb0\x5b\x2d\xd0\xf6\x5e\x2c\x14\xdf\x23\xd1\x5b\x23\x95\x83\x85\x62\xb7\x44\xc8\xde\x1e\x54\x35\xb8\xba\x70\x8f\xed\x28\x54\x43\xf6\xe2\xb9\x65\xcf\x6d\x16\xac\x2f\x14\xfb\xc7\xc1\x71\x27\xb5\xf2\x67\xc9\xe8\x6c\xb9\x84\xf7\x5b\x84\xc1\x42\xd7\x81\x57\x22\x2d\x70\x05\x5c\xf0\xd6\x51\x8e\x34\xf0\xa6\xd1\xf7\x1e\xf8\x83\x45\x42\x5b\x1b\x21\x15\x37\x8f\x5e\x47\x7d\x50\x15\x29\x06\x6e\x83\x2e\x16\x4d\xc0\x9e\x4c\x6a\xc3\xe6\x33\xaf\x37\x35\x44\x87\xf2\x4a\x2b\x87\x0f\x8e\x10\xa1\xff\x25\x0c\x71\x74\x5d\x01\x79\x0f\x5d\xd7\xb1\x7f\xf3\xe6\x80\x25\xa0\x31\xda\x14\xc1\x75\x1f\x0f\x42\xc5\x9b\xc6\x42\x9d\x57\xee\xa1\x84\x7d\xc1\xe6\x33\x52\x0d\x79\x9d\x9a\x2b\xa2\x34\x49\xc1\xc4\xea\x1e\x12\x4b\x3d\x4c\x17\xec\xc3\x71\x3e\x9b\xed\xef\x4a\xd0\x3b\x02\x7c\xcf\xf2\xd4\xef\xf9\x6c\x26\x6b\x78\xa6\x77\x5e\x6c\x66\xd0\x1d\x8c\x02\x25\x9b\x12\xea\xbd\x63\x6f\x48\x45\x9d\x67\x07\x85\x0f\x2d\x56\x0e\x45\x80\x89\x00\xf4\x2a\x9e\xbf\x67\x10\x58\x29\x1c\x19\x05\x37\x9f\xcd\xba\xf9\xa0\xb2\x8f\xf9\xae\x98\xcf\x4e\x6a\x72\xb9\x84\x95\x56\x42\x7a\x9d\x94\x4c\xa0\xa2\xa6\xb8\x23\xad\xcf\x18\x9b\x7b\xed\xab\x13\xc6\xe7\xb3\x32\x41\xe7\xa3\xd6\x8d\x37\x75\xad\x04\x6c\x8c\x3e\xb4\x76\xb4\x60\x43\x7f\xf9\xf6\xbe\xfd\x01\x74\x8b\x26\x14\x82\xcf\xcd\xb5\x12\x79\x2d\x8d\x75\x25\x58\xa4\x33\xa3\x07\x25\xcd\x0f\x07\x8c\xb1\x81\x54\x24\xfe\x1d\xe7\x43\xf0\xde\xd3\x3f\x90\x4d\xf2\xd7\x67\x84\x92\xe3\xad\xf7\x25\x03\x9f\x3e\xc1\xb3\xe0\xc8\x40\x4a\x53\x57\xf3\xc6\x62\x84\xbe\xd6\x06\x3e\x94\x3e\x50\x4a\x7d\x68\x5a\xef\xb2\x3f\x41\xba\xa7\x7a\xce\x15\x79\x4d\x49\x22\x9d\x39\x20\xa5\x30\xa4\x6e\x6d\x2e\xc1\xb9\xfe\xe9\x1c\xcd\xb5\xf9\x73\xc1\x9c\x60\x79\x01\xca\x10\xe9\x13\x91\xfc\x32\x90\x51\xcd\x39\x8e\x11\xdf\x1e\xc8\x5b\xed\x40\xe1\x86\x3b\xa4\x16\xd8\xc8\x3b\x54\x23\xa4\x11\xbc\x5b\xed\xf2\x53\xd0\xbe\x35\x42\x51\xc1\x49\x59\x8c\x3e\xbe\xe3\x76\xdd\x86\x1e\x1d\xdb\xd3\xa1\x75\x52\x6d\xc6\xb9\x10\x32\x3e\x7a\xed\x4f\xe5\xba\x4d\x4d\xaf\xdb\x0b\x9e\x7f\xf8\x6a\xbf\xf7\x6c\xdd\xe6\x05\xbb\xb1\xb9\x6e\x7b\xbf\xe9\x20\x79\x6b\x29\x71\x42\x56\x0e\xb2\x77\xdc\xbe\x95\xd8\x08\x9b\x41\xe6\x3f\x64\x9e\x76\x2d\x04\x8a\x81\x31\x7e\x0b\xdc\x55\x83\xdc\x24\x7c\xff\x21\x12\x33\xb8\xf2\x17\xed\x55\x7f\x31\xf6\x85\xb2\xc3\x47\xdb\x9b\xef\xaf\xbe\x3d\xba\xad\xf6\xdc\x0d\xba\x9e\x19\x4e\x90\x16\xba\x2d\x7a\x9f\xe9\xee\x39\x83\xfb\x8e\x37\x52\x70\x8f\xf8\x6f\x2c\x51\xd7\x75\xbf\x01\xcd\x44\xef\x5e\x7f\xaf\x24\x7a\x72\xcf\x01\xeb\x8c\x54\x9b\x32\xca\x51\xb7\x05\xca\x59\x3a\xfe\xd7\x7c\x50\x47\x1c\x8f\x20\x6b\x50\x38\xb8\x78\x06\x59\xd7\x7d\xf0\xd3\x3a\x5c\x04\xf8\x20\xad\xb3\xe1\x86\x3a\x09\x2b\x38\x5e\xbc\x82\x67\x51\xe4\xcb\x53\xaa\x6f\xd3\x10\xea\xd0\xa7\x31\xd6\x70\xee\xff\xee\xd8\xc4\xb3\xe0\x5a\xf7\xd9\xc1\x12\x8a\x26\xb9\x0a\x6f\x6a\xc0\x07\xac\x0e\x34\x06\x68\x82\x86\x41\xe0\x6f\xc4\xb0\x84\x26\x33\x61\xb9\x9c\x2f\x97\x33\xe2\xb1\x9b\x3a\x5f\xe9\x7d\x7b\x70\x78\x7d\x87\x86\x6f\xb0\xf4\xf7\xd6\x50\xe8\x39\x63\xac\x28\xe1\xb4\xc8\x3d\xb1\x28\x48\x8f\xaf\x96\x9b\x3a\xdf\xee\xd2\xc4\xbe\xd3\x7a\x17\x87\x5e\x32\x71\xce\x04\xce\xbb\x57\xe1\x83\x9b\x54\x87\xdf\x43\x26\xb4\xb4\xd2\xce\xb9\x48\xfb\x62\xfe\x87\x27\xd9\xe5\x35\xe8\xf2\xa0\xde\xee\xbc\xf3\x05\x1b\xd7\xaf\xb8\xc7\x9c\x64\x8f\x64\xa6\x22\x5d\x32\x27\xd7\xea\x8b\x49\xd4\xaa\x79\x04\x2a\xd3\x91\x9e\xcc\xcb\x24\xa3\x6b\x95\xff\xa8\x37\x27\xeb\xcc\x0f\xd8\xa0\xc3\x4f\x09\x65\x65\x90\x3b\x1c\x33\xb8\x56\x9f\xcd\xe0\x74\xf6\x7e\x39\x87\xbe\x08\xca\x61\x68\x17\x45\x8c\xe9\x67\xd5\xa0\xb5\x60\x77\xb2\xfd\xfa\xa0\x82\x92\x49\x60\x3f\xb7\x82\x9f\x06\x16\x28\x6b\x95\xc4\x16\xcf\x7e\xa3\xf8\xe8\x2a\x1d\x63\xec\x83\x7c\x2b\x1f\x50\xf8\x9d\x37\xd9\x44\xc3\x41\x1a\xb8\x1c\x6a\x12\x08\x15\x15\x6f\xb7\xf1\x48\x8e\xc6\x0c\xc5\x76\xb9\x47\xbe\x6d\x7b\x3c\x69\x03\xfe\x9d\xc6\x48\x17\x7f\x34\x26\x2d\x68\x02\xe6\x27\xfc\x0f\xad\xf8\x41\x6a\x40\xc6\x6d\x39\xd1\x88\x65\xe9\xd9\x35\x66\xdd\x06\xde\x9e\xbb\x6a\x0b\xba\xed\x8b\x20\x3c\x76\xde\x17\x40\xa0\xd8\xbc\x80\x5f\x7e\x9d\x22\xb5\x5c\x0e\xee\x4c\xd8\x81\x3b\x0b\xee\xe4\x17\x7b\x23\x94\x50\x51\xfa\x13\x1d\xfd\xed\x86\x5a\x8a\xe7\x9f\x54\x37\x5b\xff\x6c\x4a\xd2\x9c\xbe\x8b\x9e\xdb\x31\x66\x2a\x19\xa5\x5d\x78\x7f\xa2\xc8\xa8\x2e\x8b\x62\x48\xbc\xef\x4d\x4f\x8b\xc5\xb6\xda\x72\xa9\x80\x7b\xec\x08\xd2\x46\x5a\x47\xcf\x55\x82\x96\xde\xb4\x82\x14\x62\x5d\x63\xe5\xe4\x1d\x36\x8f\x20\xf7\xb4\x63\x7d\x6c\x90\x85\x21\x53\x21\x54\x7e\x00\x88\x12\xa4\x83\x7b\xd9\x34\xc0\x9b\x7b\xfe\x68\x61\xab\x1b\xe1\xbb\xd1\xd2\x93\xd2\x62\xa2\x38\xfe\x28\xe1\x19\xda\x08\x34\xfd\xbb\xca\xbb\x63\x9d\x39\x54\x7e\xab\x0d\xd2\x93\x0c\xf4\xeb\x2a\xde\x87\x03\xc1\x03\xf2\x5f\xe1\x3d\x54\x9e\xd6\xdb\xea\xd7\xd6\x28\x9b\x07\x95\x8c\xb1\x33\x9d\x45\x34\x3e\x76\x89\xff\x7e\xe4\x6d\x8b\x4a\xe4\x13\x1f\x72\x25\x9b\xa2\x8c\x36\x18\x2b\x86\xfd\xd4\x3f\x1c\xe9\x68\x18\x51\x53\x44\xfb\x02\x26\x6e\x2d\x15\x6f\x3c\x2f\xfa\x99\x57\xc1\x6e\x28\xcf\xfc\x77\xbb\x78\xdf\xb7\xe9\xd3\xbb\x99\x86\xa4\xa4\x7a\x6a\x50\xe5\x15\xf3\x8e\x15\x70\x05\xdf\xbd\x02\x09\x7f\x7f\x0d\x2f\x5f\x81\xbc\xba\x0a\x2d\xd9\xab\x7f\x0d\x51\xf0\x17\xf9\x6b\x6f\xf3\xec\x71\x1d\xa9\xe3\x0d\x74\xed\x91\x8b\x3f\x19\xf9\x05\x92\x02\x2b\x81\x0b\x41\x83\xcc\x17\x40\x8b\x95\xac\x25\x0a\x0f\x01\x1d\xe2\x11\x35\x4e\xa8\x29\x1c\x4a\x65\xd8\xec\xeb\x46\xdf\x4f\xb0\x0a\xa6\x9e\x92\x5b\x85\xf7\xbe\xef\xfd\x2e\xc5\x77\x38\x4d\x6c\x09\x2f\xcb\x13\x68\xfe\x42\x5f\xc2\xc7\x22\x51\xf0\x1a\x62\x69\xf4\x94\xb2\xc7\x88\xca\xe1\xb2\x60\x22\x76\x52\x6c\xbd\x44\x0f\xe1\x9b\xf0\x73\xdb\xd3\x20\xf4\xbc\xaf\xc7\x30\xd8\xca\x43\xf7\x44\xda\x79\x4b\x54\x2c\x22\xed\xa5\x92\x68\xc3\x1b\x27\xee\x90\xff\x0d\x00\x00\xff\xff\x27\x1e\xba\x4e\x06\x15\x00\x00") func templateHookTmplBytes() ([]byte, error) { return bindataRead( @@ -985,7 +985,7 @@ func templateHookTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/hook.tmpl", size: 5268, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/hook.tmpl", size: 5382, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/hook.tmpl b/entc/gen/template/hook.tmpl index 3a7ba14ad..f356e6745 100644 --- a/entc/gen/template/hook.tmpl +++ b/entc/gen/template/hook.tmpl @@ -129,6 +129,16 @@ func Unless(hk {{ $pkg }}.Hook, op {{ $pkg }}.Op) {{ $pkg }}.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) {{ $pkg }}.Hook { + return func({{ $pkg }}.Mutator) {{ $pkg }}.Mutator { + return {{ $pkg }}.MutateFunc(func(context.Context, {{ $pkg }}.Mutation) ({{ $pkg }}.Value, error) { + return nil, err + }) + } +} + + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []{{ $pkg }}.Hook { @@ -138,11 +148,7 @@ func Unless(hk {{ $pkg }}.Hook, op {{ $pkg }}.Op) {{ $pkg }}.Hook { // } // func Reject(op {{ $pkg }}.Op) {{ $pkg }}.Hook { - hk := func({{ $pkg }}.Mutator) {{ $pkg }}.Mutator { - return {{ $pkg }}.MutateFunc(func(_ context.Context, m {{ $pkg }}.Mutation) ({{ $pkg }}.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/config/ent/hook/hook.go b/entc/integration/config/ent/hook/hook.go index 4db8d60fb..b0be3771e 100644 --- a/entc/integration/config/ent/hook/hook.go +++ b/entc/integration/config/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/customid/ent/hook/hook.go b/entc/integration/customid/ent/hook/hook.go index 392d4cb49..333a82e97 100644 --- a/entc/integration/customid/ent/hook/hook.go +++ b/entc/integration/customid/ent/hook/hook.go @@ -201,6 +201,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -210,11 +219,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/ent/hook/hook.go b/entc/integration/ent/hook/hook.go index 1d73ed22f..2fc82e5a1 100644 --- a/entc/integration/ent/hook/hook.go +++ b/entc/integration/ent/hook/hook.go @@ -318,6 +318,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -327,11 +336,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/gremlin/ent/hook/hook.go b/entc/integration/gremlin/ent/hook/hook.go index 6554b81da..46fb52bf4 100644 --- a/entc/integration/gremlin/ent/hook/hook.go +++ b/entc/integration/gremlin/ent/hook/hook.go @@ -318,6 +318,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -327,11 +336,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/hooks/ent/hook/hook.go b/entc/integration/hooks/ent/hook/hook.go index 2ab969853..5e2e3fadc 100644 --- a/entc/integration/hooks/ent/hook/hook.go +++ b/entc/integration/hooks/ent/hook/hook.go @@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/idtype/ent/hook/hook.go b/entc/integration/idtype/ent/hook/hook.go index 8e110c53f..8337e85a7 100644 --- a/entc/integration/idtype/ent/hook/hook.go +++ b/entc/integration/idtype/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/json/ent/hook/hook.go b/entc/integration/json/ent/hook/hook.go index 8d264ffb2..1b129a54e 100644 --- a/entc/integration/json/ent/hook/hook.go +++ b/entc/integration/json/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/migrate/entv1/hook/hook.go b/entc/integration/migrate/entv1/hook/hook.go index a3568aec3..284829e64 100644 --- a/entc/integration/migrate/entv1/hook/hook.go +++ b/entc/integration/migrate/entv1/hook/hook.go @@ -162,6 +162,15 @@ func Unless(hk entv1.Hook, op entv1.Op) entv1.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) entv1.Hook { + return func(entv1.Mutator) entv1.Mutator { + return entv1.MutateFunc(func(context.Context, entv1.Mutation) (entv1.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []entv1.Hook { @@ -171,11 +180,7 @@ func Unless(hk entv1.Hook, op entv1.Op) entv1.Hook { // } // func Reject(op entv1.Op) entv1.Hook { - hk := func(entv1.Mutator) entv1.Mutator { - return entv1.MutateFunc(func(_ context.Context, m entv1.Mutation) (entv1.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/migrate/entv2/hook/hook.go b/entc/integration/migrate/entv2/hook/hook.go index 365364224..cee5fb7d6 100644 --- a/entc/integration/migrate/entv2/hook/hook.go +++ b/entc/integration/migrate/entv2/hook/hook.go @@ -201,6 +201,15 @@ func Unless(hk entv2.Hook, op entv2.Op) entv2.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) entv2.Hook { + return func(entv2.Mutator) entv2.Mutator { + return entv2.MutateFunc(func(context.Context, entv2.Mutation) (entv2.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []entv2.Hook { @@ -210,11 +219,7 @@ func Unless(hk entv2.Hook, op entv2.Op) entv2.Hook { // } // func Reject(op entv2.Op) entv2.Hook { - hk := func(entv2.Mutator) entv2.Mutator { - return entv2.MutateFunc(func(_ context.Context, m entv2.Mutation) (entv2.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/privacy/ent/hook/hook.go b/entc/integration/privacy/ent/hook/hook.go index 422efdf40..5650147ef 100644 --- a/entc/integration/privacy/ent/hook/hook.go +++ b/entc/integration/privacy/ent/hook/hook.go @@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/entc/integration/template/ent/hook/hook.go b/entc/integration/template/ent/hook/hook.go index 2e3813e8b..86d7bad14 100644 --- a/entc/integration/template/ent/hook/hook.go +++ b/entc/integration/template/ent/hook/hook.go @@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/edgeindex/ent/hook/hook.go b/examples/edgeindex/ent/hook/hook.go index 0c1da84a0..b2df98813 100644 --- a/examples/edgeindex/ent/hook/hook.go +++ b/examples/edgeindex/ent/hook/hook.go @@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/entcpkg/ent/hook/hook.go b/examples/entcpkg/ent/hook/hook.go index 4add8722d..3fb4df341 100644 --- a/examples/entcpkg/ent/hook/hook.go +++ b/examples/entcpkg/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/m2m2types/ent/hook/hook.go b/examples/m2m2types/ent/hook/hook.go index 074ed6ded..ae69bd96c 100644 --- a/examples/m2m2types/ent/hook/hook.go +++ b/examples/m2m2types/ent/hook/hook.go @@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/m2mbidi/ent/hook/hook.go b/examples/m2mbidi/ent/hook/hook.go index 5c7a08e05..da65a7346 100644 --- a/examples/m2mbidi/ent/hook/hook.go +++ b/examples/m2mbidi/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/m2mrecur/ent/hook/hook.go b/examples/m2mrecur/ent/hook/hook.go index 85e6e3966..0a772b426 100644 --- a/examples/m2mrecur/ent/hook/hook.go +++ b/examples/m2mrecur/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/o2m2types/ent/hook/hook.go b/examples/o2m2types/ent/hook/hook.go index bc68e3d82..b43c580ff 100644 --- a/examples/o2m2types/ent/hook/hook.go +++ b/examples/o2m2types/ent/hook/hook.go @@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/o2mrecur/ent/hook/hook.go b/examples/o2mrecur/ent/hook/hook.go index 60237ad17..9f2202359 100644 --- a/examples/o2mrecur/ent/hook/hook.go +++ b/examples/o2mrecur/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/o2o2types/ent/hook/hook.go b/examples/o2o2types/ent/hook/hook.go index 93e332d84..83f0a2891 100644 --- a/examples/o2o2types/ent/hook/hook.go +++ b/examples/o2o2types/ent/hook/hook.go @@ -162,6 +162,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -171,11 +180,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/o2obidi/ent/hook/hook.go b/examples/o2obidi/ent/hook/hook.go index 730da80db..0f38f6697 100644 --- a/examples/o2obidi/ent/hook/hook.go +++ b/examples/o2obidi/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/o2orecur/ent/hook/hook.go b/examples/o2orecur/ent/hook/hook.go index 280c55975..5869422ed 100644 --- a/examples/o2orecur/ent/hook/hook.go +++ b/examples/o2orecur/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/privacyadmin/ent/hook/hook.go b/examples/privacyadmin/ent/hook/hook.go index bf273ecd0..fa57227d1 100644 --- a/examples/privacyadmin/ent/hook/hook.go +++ b/examples/privacyadmin/ent/hook/hook.go @@ -149,6 +149,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -158,11 +167,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/privacytenant/ent/hook/hook.go b/examples/privacytenant/ent/hook/hook.go index 159f8f325..37b4b69da 100644 --- a/examples/privacytenant/ent/hook/hook.go +++ b/examples/privacytenant/ent/hook/hook.go @@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/start/ent/hook/hook.go b/examples/start/ent/hook/hook.go index 3854b155e..969ed54f1 100644 --- a/examples/start/ent/hook/hook.go +++ b/examples/start/ent/hook/hook.go @@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) } diff --git a/examples/traversal/ent/hook/hook.go b/examples/traversal/ent/hook/hook.go index d3fa96b95..d92bce85f 100644 --- a/examples/traversal/ent/hook/hook.go +++ b/examples/traversal/ent/hook/hook.go @@ -175,6 +175,15 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { return If(hk, Not(HasOp(op))) } +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + // Reject returns a hook that rejects all operations that match op. // // func (T) Hooks() []ent.Hook { @@ -184,11 +193,7 @@ func Unless(hk ent.Hook, op ent.Op) ent.Hook { // } // func Reject(op ent.Op) ent.Hook { - hk := func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) { - return nil, fmt.Errorf("%s operation is not allowed", m.Op()) - }) - } + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) }