Improved Errors - Pick up on the new task_trace information in WorkflowException and pass it on through the api.

Also:  All script tasks should raise WorkflowTaskExecExceptions - NOT APIExceptions - this is because our scripts are executed by Spiff (not the other way around)  so the errors need to pass fluidly through spiff, and come back to use THEN we can convert them to APIErrors.  Otherwise we lose all kinds of good information about the error.
This commit is contained in:
Dan 2022-03-14 16:00:53 -04:00
parent 90bfbed6fd
commit 483d7e858b
11 changed files with 155 additions and 164 deletions

172
Pipfile.lock generated
View File

@ -25,11 +25,11 @@
},
"alembic": {
"hashes": [
"sha256:6c0c05e9768a896d804387e20b299880fe01bc56484246b0dffe8075d6d3d847",
"sha256:ad842f2c3ab5c5d4861232730779c05e33db4ba880a08b85eb505e87c01095bc"
"sha256:29be0856ec7591c39f4e1cb10f198045d890e6e2274cf8da80cb5e721a09642b",
"sha256:4961248173ead7ce8a21efb3de378f13b8398e6630fab0eb258dc74a8af24c58"
],
"index": "pypi",
"version": "==1.7.6"
"version": "==1.7.7"
},
"amqp": {
"hashes": [
@ -549,11 +549,11 @@
},
"importlib-metadata": {
"hashes": [
"sha256:b36ffa925fe3139b2f6ff11d6925ffd4fa7bc47870165e3ac260ac7b4f91e6ac",
"sha256:d16e8c1deb60de41b8e8ed21c1a7b947b0bc62fab7e1d470bcdf331cea2e6735"
"sha256:1208431ca90a8cca1a6b8af391bb53c1a2db74e5d1cef6ddced95d4b2062edc6",
"sha256:ea4c597ebf37142f827b8f39299579e31685c31d3a438b59f469406afd0f2539"
],
"markers": "python_version < '3.10'",
"version": "==4.11.2"
"version": "==4.11.3"
},
"importlib-resources": {
"hashes": [
@ -576,7 +576,7 @@
"sha256:7b7d3023cd35d9cb0c1fd91392f8c95c6fa02c59bf8ad64b8849be3401b95afb",
"sha256:935642cd4b987cdbee7210080004033af76306757ff8b4c0a506a4b6e06f02cf"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==2.1.1"
},
"jinja2": {
@ -592,7 +592,7 @@
"sha256:636694eb41b3535ed608fe04129f26542b59ed99808b4f688aa32dcf55317a83",
"sha256:77281a1f71684953ee8b3d488371b162419767973789272434bbc3f29d9c8823"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==4.4.0"
},
"kombu": {
@ -600,7 +600,7 @@
"sha256:37cee3ee725f94ea8bb173eaab7c1760203ea53bbebae226328600f9d2799610",
"sha256:8b213b24293d3417bcf0d2f5537b7f756079e3ea232a8386dcc89a59fd2361a4"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==5.2.4"
},
"ldap3": {
@ -683,11 +683,11 @@
},
"mako": {
"hashes": [
"sha256:4e9e345a41924a954251b95b4b28e14a301145b544901332e658907a7464b6b2",
"sha256:afaf8e515d075b22fad7d7b8b30e4a1c90624ff2f3733a06ec125f5a5f043a57"
"sha256:23aab11fdbbb0f1051b93793a58323ff937e98e34aece1c4219675122e57e4ba",
"sha256:9a7c7e922b87db3686210cf49d5d767033a41d4010b284e747682c92bddd8b39"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==1.1.6"
"markers": "python_version >= '3.7'",
"version": "==1.2.0"
},
"markdown": {
"hashes": [
@ -740,16 +740,16 @@
"sha256:fabbe18087c3d33c5824cb145ffca52eccd053061df1d79d4b66dafa5ad2a5ea",
"sha256:fc3150f85e2dbcf99e65238c842d1cfe69d3e7649b19864c1cc043213d9cd730"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==2.1.0"
},
"marshmallow": {
"hashes": [
"sha256:04438610bc6dadbdddb22a4a55bcc7f6f8099e69580b2e67f5a681933a1f4400",
"sha256:4c05c1684e0e97fe779c62b91878f173b937fe097b356cd82f793464f5bc6138"
"sha256:2aaaab4f01ef4f5a011a21319af9fce17ab13bf28a026d1252adab0e035648d5",
"sha256:ff79885ed43b579782f48c251d262e062bce49c65c52412458769a4fb57ac30f"
],
"index": "pypi",
"version": "==3.14.1"
"version": "==3.15.0"
},
"marshmallow-enum": {
"hashes": [
@ -761,11 +761,11 @@
},
"marshmallow-sqlalchemy": {
"hashes": [
"sha256:1521b129564444648c523a38f6446c137f1aae5c9c7de1ec151d5ebf03fd407d",
"sha256:a11fdb628e78c70853646cd7d6d56e07fd56cc702e9675f9abb34832ea055ffe"
"sha256:f1b977c323ac0ccc0456b15d4eb9bff413b92c72d7a165f263dc276dd3782cf4",
"sha256:fb6b06686f38fec2ea0ec53a5ee4979219409e2b2260f9bc91e4b43105d19782"
],
"index": "pypi",
"version": "==0.27.0"
"version": "==0.28.0"
},
"numpy": {
"hashes": [
@ -786,6 +786,7 @@
"sha256:dbc7601a3b7472d559dc7b933b18b4b66f9aa7452c120e87dfb33d02008c8a18",
"sha256:e7927a589df200c5e23c57970bafbd0cd322459aa7b1ff73b7c2e84d6e3eae62",
"sha256:f8c1f39caad2c896bc0018f699882b345b2a63708008be29b1f355ebf6f933fe",
"sha256:f950f8845b480cffe522913d35567e29dd381b0dc7e4ce6a4a9f9156417d2430",
"sha256:fade0d4f4d292b6f39951b6836d7a3c7ef5b2347f3c420cd9820a1d90d794802",
"sha256:fdf3c08bce27132395d3c3ba1503cac12e17282358cb4bddc25cc46b0aca07aa"
],
@ -1003,7 +1004,7 @@
"sha256:f87cc2863ef33c709e237d4b5f4502a62a00fab450c9e020892e8e2ede5847f5",
"sha256:fd8da6d0124efa2f67d86fa70c851022f87c98e205f0594e1fae044e7119a5a6"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==0.18.1"
},
"python-dateutil": {
@ -1266,7 +1267,7 @@
},
"spiffworkflow": {
"git": "https://github.com/sartography/SpiffWorkflow",
"ref": "61096d6e10c99fa6e9d6899d3ccfc1f1b10f5786"
"ref": "0eaf162d9f51e22165cfcd1ff0467f88b14eb814"
},
"sqlalchemy": {
"hashes": [
@ -1354,7 +1355,7 @@
"sha256:58bd2fa1c2c82adf6e322ae7151f4fbd5176d2769602407a61b9c92b1606c2ef",
"sha256:ec8a8d9b6b15f3bb2c1a82b8f3929a029c333c35fcafb08c185a9e562d8cc9c2"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==2.1.0"
},
"wcwidth": {
@ -1390,67 +1391,80 @@
},
"wrapt": {
"hashes": [
"sha256:086218a72ec7d986a3eddb7707c8c4526d677c7b35e355875a0fe2918b059179",
"sha256:0877fe981fd76b183711d767500e6b3111378ed2043c145e21816ee589d91096",
"sha256:0a017a667d1f7411816e4bf214646d0ad5b1da2c1ea13dec6c162736ff25a374",
"sha256:0cb23d36ed03bf46b894cfec777eec754146d68429c30431c99ef28482b5c1df",
"sha256:1fea9cd438686e6682271d36f3481a9f3636195578bab9ca3382e2f5f01fc185",
"sha256:220a869982ea9023e163ba915077816ca439489de6d2c09089b219f4e11b6785",
"sha256:25b1b1d5df495d82be1c9d2fad408f7ce5ca8a38085e2da41bb63c914baadff7",
"sha256:2dded5496e8f1592ec27079b28b6ad2a1ef0b9296d270f77b8e4a3a796cf6909",
"sha256:2ebdde19cd3c8cdf8df3fc165bc7827334bc4e353465048b36f7deeae8ee0918",
"sha256:43e69ffe47e3609a6aec0fe723001c60c65305784d964f5007d5b4fb1bc6bf33",
"sha256:46f7f3af321a573fc0c3586612db4decb7eb37172af1bc6173d81f5b66c2e068",
"sha256:47f0a183743e7f71f29e4e21574ad3fa95676136f45b91afcf83f6a050914829",
"sha256:498e6217523111d07cd67e87a791f5e9ee769f9241fcf8a379696e25806965af",
"sha256:4b9c458732450ec42578b5642ac53e312092acf8c0bfce140ada5ca1ac556f79",
"sha256:51799ca950cfee9396a87f4a1240622ac38973b6df5ef7a41e7f0b98797099ce",
"sha256:5601f44a0f38fed36cc07db004f0eedeaadbdcec90e4e90509480e7e6060a5bc",
"sha256:5f223101f21cfd41deec8ce3889dc59f88a59b409db028c469c9b20cfeefbe36",
"sha256:610f5f83dd1e0ad40254c306f4764fcdc846641f120c3cf424ff57a19d5f7ade",
"sha256:6a03d9917aee887690aa3f1747ce634e610f6db6f6b332b35c2dd89412912bca",
"sha256:705e2af1f7be4707e49ced9153f8d72131090e52be9278b5dbb1498c749a1e32",
"sha256:766b32c762e07e26f50d8a3468e3b4228b3736c805018e4b0ec8cc01ecd88125",
"sha256:77416e6b17926d953b5c666a3cb718d5945df63ecf922af0ee576206d7033b5e",
"sha256:778fd096ee96890c10ce96187c76b3e99b2da44e08c9e24d5652f356873f6709",
"sha256:78dea98c81915bbf510eb6a3c9c24915e4660302937b9ae05a0947164248020f",
"sha256:7dd215e4e8514004c8d810a73e342c536547038fb130205ec4bba9f5de35d45b",
"sha256:7dde79d007cd6dfa65afe404766057c2409316135cb892be4b1c768e3f3a11cb",
"sha256:81bd7c90d28a4b2e1df135bfbd7c23aee3050078ca6441bead44c42483f9ebfb",
"sha256:85148f4225287b6a0665eef08a178c15097366d46b210574a658c1ff5b377489",
"sha256:865c0b50003616f05858b22174c40ffc27a38e67359fa1495605f96125f76640",
"sha256:87883690cae293541e08ba2da22cacaae0a092e0ed56bbba8d018cc486fbafbb",
"sha256:8aab36778fa9bba1a8f06a4919556f9f8c7b33102bd71b3ab307bb3fecb21851",
"sha256:8c73c1a2ec7c98d7eaded149f6d225a692caa1bd7b2401a14125446e9e90410d",
"sha256:936503cb0a6ed28dbfa87e8fcd0a56458822144e9d11a49ccee6d9a8adb2ac44",
"sha256:944b180f61f5e36c0634d3202ba8509b986b5fbaf57db3e94df11abee244ba13",
"sha256:96b81ae75591a795d8c90edc0bfaab44d3d41ffc1aae4d994c5aa21d9b8e19a2",
"sha256:981da26722bebb9247a0601e2922cedf8bb7a600e89c852d063313102de6f2cb",
"sha256:ae9de71eb60940e58207f8e71fe113c639da42adb02fb2bcbcaccc1ccecd092b",
"sha256:b73d4b78807bd299b38e4598b8e7bd34ed55d480160d2e7fdaabd9931afa65f9",
"sha256:d4a5f6146cfa5c7ba0134249665acd322a70d1ea61732723c7d3e8cc0fa80755",
"sha256:dd91006848eb55af2159375134d724032a2d1d13bcc6f81cd8d3ed9f2b8e846c",
"sha256:e05e60ff3b2b0342153be4d1b597bbcfd8330890056b9619f4ad6b8d5c96a81a",
"sha256:e6906d6f48437dfd80464f7d7af1740eadc572b9f7a4301e7dd3d65db285cacf",
"sha256:e92d0d4fa68ea0c02d39f1e2f9cb5bc4b4a71e8c442207433d8db47ee79d7aa3",
"sha256:e94b7d9deaa4cc7bac9198a58a7240aaf87fe56c6277ee25fa5b3aa1edebd229",
"sha256:ea3e746e29d4000cd98d572f3ee2a6050a4f784bb536f4ac1f035987fc1ed83e",
"sha256:ec7e20258ecc5174029a0f391e1b948bf2906cd64c198a9b8b281b811cbc04de",
"sha256:ec9465dd69d5657b5d2fa6133b3e1e989ae27d29471a672416fd729b429eb554",
"sha256:f122ccd12fdc69628786d0c947bdd9cb2733be8f800d88b5a37c57f1f1d73c10",
"sha256:f99c0489258086308aad4ae57da9e8ecf9e1f3f30fa35d5e170b4d4896554d80",
"sha256:f9c51d9af9abb899bd34ace878fbec8bf357b3194a10c4e8e0a25512826ef056",
"sha256:fd76c47f20984b43d93de9a82011bb6e5f8325df6c9ed4d8310029a55fa361ea"
"sha256:00108411e0f34c52ce16f81f1d308a571df7784932cc7491d1e94be2ee93374b",
"sha256:01f799def9b96a8ec1ef6b9c1bbaf2bbc859b87545efbecc4a78faea13d0e3a0",
"sha256:09d16ae7a13cff43660155383a2372b4aa09109c7127aa3f24c3cf99b891c330",
"sha256:14e7e2c5f5fca67e9a6d5f753d21f138398cad2b1159913ec9e9a67745f09ba3",
"sha256:167e4793dc987f77fd476862d32fa404d42b71f6a85d3b38cbce711dba5e6b68",
"sha256:1807054aa7b61ad8d8103b3b30c9764de2e9d0c0978e9d3fc337e4e74bf25faa",
"sha256:1f83e9c21cd5275991076b2ba1cd35418af3504667affb4745b48937e214bafe",
"sha256:21b1106bff6ece8cb203ef45b4f5778d7226c941c83aaaa1e1f0f4f32cc148cd",
"sha256:22626dca56fd7f55a0733e604f1027277eb0f4f3d95ff28f15d27ac25a45f71b",
"sha256:23f96134a3aa24cc50614920cc087e22f87439053d886e474638c68c8d15dc80",
"sha256:2498762814dd7dd2a1d0248eda2afbc3dd9c11537bc8200a4b21789b6df6cd38",
"sha256:28c659878f684365d53cf59dc9a1929ea2eecd7ac65da762be8b1ba193f7e84f",
"sha256:2eca15d6b947cfff51ed76b2d60fd172c6ecd418ddab1c5126032d27f74bc350",
"sha256:354d9fc6b1e44750e2a67b4b108841f5f5ea08853453ecbf44c81fdc2e0d50bd",
"sha256:36a76a7527df8583112b24adc01748cd51a2d14e905b337a6fefa8b96fc708fb",
"sha256:3a0a4ca02752ced5f37498827e49c414d694ad7cf451ee850e3ff160f2bee9d3",
"sha256:3a71dbd792cc7a3d772ef8cd08d3048593f13d6f40a11f3427c000cf0a5b36a0",
"sha256:3a88254881e8a8c4784ecc9cb2249ff757fd94b911d5df9a5984961b96113fff",
"sha256:47045ed35481e857918ae78b54891fac0c1d197f22c95778e66302668309336c",
"sha256:4775a574e9d84e0212f5b18886cace049a42e13e12009bb0491562a48bb2b758",
"sha256:493da1f8b1bb8a623c16552fb4a1e164c0200447eb83d3f68b44315ead3f9036",
"sha256:4b847029e2d5e11fd536c9ac3136ddc3f54bc9488a75ef7d040a3900406a91eb",
"sha256:59d7d92cee84a547d91267f0fea381c363121d70fe90b12cd88241bd9b0e1763",
"sha256:5a0898a640559dec00f3614ffb11d97a2666ee9a2a6bad1259c9facd01a1d4d9",
"sha256:5a9a1889cc01ed2ed5f34574c90745fab1dd06ec2eee663e8ebeefe363e8efd7",
"sha256:5b835b86bd5a1bdbe257d610eecab07bf685b1af2a7563093e0e69180c1d4af1",
"sha256:5f24ca7953f2643d59a9c87d6e272d8adddd4a53bb62b9208f36db408d7aafc7",
"sha256:61e1a064906ccba038aa3c4a5a82f6199749efbbb3cef0804ae5c37f550eded0",
"sha256:65bf3eb34721bf18b5a021a1ad7aa05947a1767d1aa272b725728014475ea7d5",
"sha256:6807bcee549a8cb2f38f73f469703a1d8d5d990815c3004f21ddb68a567385ce",
"sha256:68aeefac31c1f73949662ba8affaf9950b9938b712fb9d428fa2a07e40ee57f8",
"sha256:6915682f9a9bc4cf2908e83caf5895a685da1fbd20b6d485dafb8e218a338279",
"sha256:6d9810d4f697d58fd66039ab959e6d37e63ab377008ef1d63904df25956c7db0",
"sha256:729d5e96566f44fccac6c4447ec2332636b4fe273f03da128fff8d5559782b06",
"sha256:748df39ed634851350efa87690c2237a678ed794fe9ede3f0d79f071ee042561",
"sha256:763a73ab377390e2af26042f685a26787c402390f682443727b847e9496e4a2a",
"sha256:8323a43bd9c91f62bb7d4be74cc9ff10090e7ef820e27bfe8815c57e68261311",
"sha256:8529b07b49b2d89d6917cfa157d3ea1dfb4d319d51e23030664a827fe5fd2131",
"sha256:87fa943e8bbe40c8c1ba4086971a6fefbf75e9991217c55ed1bcb2f1985bd3d4",
"sha256:88236b90dda77f0394f878324cfbae05ae6fde8a84d548cfe73a75278d760291",
"sha256:891c353e95bb11abb548ca95c8b98050f3620a7378332eb90d6acdef35b401d4",
"sha256:89ba3d548ee1e6291a20f3c7380c92f71e358ce8b9e48161401e087e0bc740f8",
"sha256:8c6be72eac3c14baa473620e04f74186c5d8f45d80f8f2b4eda6e1d18af808e8",
"sha256:9a242871b3d8eecc56d350e5e03ea1854de47b17f040446da0e47dc3e0b9ad4d",
"sha256:9a3ff5fb015f6feb78340143584d9f8a0b91b6293d6b5cf4295b3e95d179b88c",
"sha256:9a5a544861b21e0e7575b6023adebe7a8c6321127bb1d238eb40d99803a0e8bd",
"sha256:9d57677238a0c5411c76097b8b93bdebb02eb845814c90f0b01727527a179e4d",
"sha256:9d8c68c4145041b4eeae96239802cfdfd9ef927754a5be3f50505f09f309d8c6",
"sha256:9d9fcd06c952efa4b6b95f3d788a819b7f33d11bea377be6b8980c95e7d10775",
"sha256:a0057b5435a65b933cbf5d859cd4956624df37b8bf0917c71756e4b3d9958b9e",
"sha256:a65bffd24409454b889af33b6c49d0d9bcd1a219b972fba975ac935f17bdf627",
"sha256:b0ed6ad6c9640671689c2dbe6244680fe8b897c08fd1fab2228429b66c518e5e",
"sha256:b21650fa6907e523869e0396c5bd591cc326e5c1dd594dcdccac089561cacfb8",
"sha256:b3f7e671fb19734c872566e57ce7fc235fa953d7c181bb4ef138e17d607dc8a1",
"sha256:b77159d9862374da213f741af0c361720200ab7ad21b9f12556e0eb95912cd48",
"sha256:bb36fbb48b22985d13a6b496ea5fb9bb2a076fea943831643836c9f6febbcfdc",
"sha256:d066ffc5ed0be00cd0352c95800a519cf9e4b5dd34a028d301bdc7177c72daf3",
"sha256:d332eecf307fca852d02b63f35a7872de32d5ba8b4ec32da82f45df986b39ff6",
"sha256:d808a5a5411982a09fef6b49aac62986274ab050e9d3e9817ad65b2791ed1425",
"sha256:d9bdfa74d369256e4218000a629978590fd7cb6cf6893251dad13d051090436d",
"sha256:db6a0ddc1282ceb9032e41853e659c9b638789be38e5b8ad7498caac00231c23",
"sha256:debaf04f813ada978d7d16c7dfa16f3c9c2ec9adf4656efdc4defdf841fc2f0c",
"sha256:f0408e2dbad9e82b4c960274214af533f856a199c9274bd4aff55d4634dedc33",
"sha256:f2f3bc7cd9c9fcd39143f11342eb5963317bd54ecc98e3650ca22704b69d9653"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==1.13.3"
"version": "==1.14.0"
},
"wtforms": {
"hashes": [
"sha256:6b351bbb12dd58af57ffef05bc78425d08d1914e0fd68ee14143b7ade023c5bc",
"sha256:837f2f0e0ca79481b92884962b914eba4e72b7a2daaf1f939c890ed0124b834b"
],
"markers": "python_full_version >= '3.7.0'",
"markers": "python_version >= '3.7'",
"version": "==3.0.1"
},
"xlrd": {
@ -1583,11 +1597,11 @@
},
"pytest": {
"hashes": [
"sha256:9ce3ff477af913ecf6321fe337b93a2c0dcf2a0a1439c43f5452112c1e4280db",
"sha256:e30905a0c131d3d94b89624a1cc5afec3e0ba2fbdb151867d8e0ebd49850f171"
"sha256:b555252a95bbb2a37a97b5ac2eb050c436f7989993565f5e0c9128fcaacadd0e",
"sha256:f1089d218cfcc63a212c42896f1b7fbf096874d045e1988186861a1a87d27b47"
],
"index": "pypi",
"version": "==7.0.1"
"version": "==7.1.0"
},
"tomli": {
"hashes": [

View File

@ -159,7 +159,7 @@ def validate_all(study_id, category=None, spec_id=None):
if e.code == 'disabled_workflow':
print(f"Skipping {spec.id} in category {spec.category.display_name}, it is disabled for this study.")
else:
print(f"API Error {e.code}, validate workflow {spec.id} in Category {spec.category.display_name}")
print(f"API Error {e.code}, validate workflow {spec.id} in Category {spec.category.display_name}. {e.message}")
continue
except WorkflowTaskExecException as e:
print(f"Workflow Error, {e}, in Task {e.task.name} validate workflow {spec.id} in Category {spec.category.display_name}")

View File

@ -14,7 +14,8 @@ import sentry_sdk
class ApiError(Exception):
def __init__(self, code, message, status_code=400,
file_name="", task_id="", task_name="", tag="",
task_data=None, error_type="", error_line="", line_number=0, offset=0):
task_data=None, error_type="", error_line="", line_number=0, offset=0,
task_trace=[]):
if task_data is None:
task_data = {}
self.status_code = status_code
@ -29,6 +30,8 @@ class ApiError(Exception):
self.offset = offset
self.error_type = error_type
self.error_line = error_line
self.task_stack = task_trace
try:
user = g.user.uid
except Exception as e:
@ -49,7 +52,8 @@ class ApiError(Exception):
return msg
@classmethod
def from_task(cls, code, message, task, status_code=400, line_number=0, offset=0, error_type="", error_line=""):
def from_task(cls, code, message, task, status_code=400, line_number=0, offset=0, error_type="", error_line="",
task_trace=None):
"""Constructs an API Error with details pulled from the current task."""
instance = cls(code, message, status_code=status_code)
instance.task_id = task.task_spec.name or ""
@ -59,6 +63,10 @@ class ApiError(Exception):
instance.offset = offset
instance.error_type = error_type
instance.error_line = error_line
if task_trace:
instance.task_trace = task_trace
else:
instance.task_trace = WorkflowTaskExecException.get_task_trace(task)
# Fixme: spiffworkflow is doing something weird where task ends up referenced in the data in some cases.
if "task" in task.data:
@ -108,7 +116,8 @@ class ApiError(Exception):
return ApiError.from_task(code, message, exp.task, line_number=exp.line_number,
offset=exp.offset,
error_type=exp.exception.__class__.__name__,
error_line=exp.error_line)
error_line=exp.error_line,
task_trace=exp.task_trace)
else:
return ApiError.from_task_spec(code, message, exp.sender)
@ -117,7 +126,8 @@ class ApiError(Exception):
class ApiErrorSchema(ma.Schema):
class Meta:
fields = ("code", "message", "workflow_name", "file_name", "task_name", "task_id",
"task_data", "task_user", "hint", "line_number", "offset", "error_type", "error_line")
"task_data", "task_user", "hint", "line_number", "offset", "error_type",
"error_line", "task_trace")
@app.errorhandler(ApiError)

View File

@ -1,3 +1,5 @@
from SpiffWorkflow.exceptions import WorkflowTaskExecException
from crc.scripts.script import Script
from crc.api.common import ApiError
from crc.services.protocol_builder import ProtocolBuilderService
@ -19,15 +21,11 @@ class CheckStudy(Script):
if study:
return {"DETAIL": "Passed validation.", "STATUS": "No Error"}
else:
raise ApiError.from_task(code='bad_study',
message=f'No study for study_id {study_id}',
task=task)
raise WorkflowTaskExecException(task, 'Function check_study failed. There is no study for study_id {study_id}.')
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
check_study = self.pb.check_study(study_id)
if check_study:
return check_study
else:
raise ApiError.from_task(code='missing_check_study',
message='There was a problem checking information for this study.',
task=task)
raise WorkflowTaskExecException(task, 'There was a problem checking information for this study.')

View File

@ -1,3 +1,5 @@
from SpiffWorkflow.exceptions import WorkflowTaskExecException
from crc import session
from crc.api.common import ApiError
from crc.models.file import FileModel
@ -17,13 +19,11 @@ class DeleteFile(Script):
for file in result:
UserFileService.delete_file(file.id)
else:
raise ApiError.from_task(code='no_document_found',
message=f'No document of type {doc_code} was found for this workflow.',
task=task)
raise WorkflowTaskExecException(task, f'delete_file() failed. No document of type {doc_code}'
f' was found for this workflow.')
else:
raise ApiError.from_task(code='invalid_document_code',
message=f'{doc_code} is not a valid document code',
task=task)
raise WorkflowTaskExecException(task, f'delete_file() failed. {doc_code} is not valid document code.')
def get_codes(self, task, args, kwargs):
if 'code' in kwargs:
@ -40,8 +40,8 @@ class DeleteFile(Script):
codes.append(arg)
if codes is None or len(codes) == 0:
raise ApiError.from_task("invalid_argument", "Please provide a valid document code to delete. "
"No valid arguments found.", task=task)
raise WorkflowTaskExecException(task, f'delete_file() failed. Please provide a document code.')
return codes
def get_description(self):

View File

@ -1,3 +1,5 @@
from SpiffWorkflow.exceptions import WorkflowTaskExecException
from crc.scripts.script import Script
from crc.api.common import ApiError
from crc import session
@ -26,9 +28,8 @@ class EmailData(Script):
return EmailModelSchema(many=True).dump([email_model])
else:
raise ApiError.from_task(code='missing_email_id',
message='You must include an email_id or workflow_spec_id with the get_email_data script.',
task=task)
raise WorkflowTaskExecException(task, f'get_email_data() failed. You must include an email_id or '
f'workflow_spec_id with the get_email_data script.')
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
email_models = None
@ -41,9 +42,8 @@ class EmailData(Script):
.filter(EmailModel.workflow_spec_id == str(kwargs['workflow_spec_id']))\
.all()
else:
raise ApiError.from_task(code='missing_email_id',
message='You must include an email_id or workflow_spec_id with the get_email_data script.',
task=task)
raise WorkflowTaskExecException(task, f'get_email_data() failed. You must include an email_id or '
f'workflow_spec_id with the get_email_data script.')
if email_models:
email_data = EmailModelSchema(many=True).dump(email_models)

View File

@ -1,3 +1,5 @@
from SpiffWorkflow.exceptions import WorkflowTaskExecException
from crc.scripts.script import Script
from crc.api.common import ApiError
@ -19,6 +21,5 @@ class IRBInfo(Script):
if irb_info:
return irb_info
else:
raise ApiError.from_task(code='missing_irb_info',
message=f'There was a problem retrieving IRB Info for study {study_id}.',
task=task)
raise WorkflowTaskExecException(task, f'get_irb_info failed. There was a problem retrieving IRB Info'
f' for study {study_id}.')

View File

@ -1,3 +1,5 @@
from SpiffWorkflow.exceptions import WorkflowTaskExecException
from crc import session
from crc.api.common import ApiError
from crc.models.workflow import WorkflowModel, WorkflowStatus
@ -22,9 +24,8 @@ Examples:
if 'workflow_spec_id' in kwargs.keys() or len(args) > 0:
return WorkflowStatus.not_started.value
else:
raise ApiError.from_task(code='missing_argument',
message='You must include a workflow_spec_id when calling the `get_workflow_status` script.',
task=task)
raise WorkflowTaskExecException(task, f'get_workflow_status() failed. You must include a workflow_spec_id'
f' when calling the `get_workflow_status` script.')
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
if 'workflow_spec_id' in kwargs.keys() or len(args) > 0:
@ -42,6 +43,5 @@ Examples:
return WorkflowStatus.not_started.value
else:
raise ApiError.from_task(code='missing_argument',
message='You must include a workflow_spec_id when calling the `get_workflow_status` script.',
task=task)
raise WorkflowTaskExecException(task, f'get_workflow_status() failed. You must include a workflow_spec_id'
f' when calling the `get_workflow_status` script.')

View File

@ -1,3 +1,5 @@
from SpiffWorkflow.exceptions import WorkflowTaskExecException
from crc import session
from crc.api.common import ApiError
from crc.models.study import StudyModel, ProgressStatus
@ -10,58 +12,27 @@ class SetStudyProgressStatus(Script):
return """Set the progress status of the current study.
Progress status can be one of `in_progress`, `submitted_for_pre_review`, `in_pre_review`, `returned_from_pre_review`, `pre_review_complete`, `agenda_date_set`, `approved`, `approved_with_conditions`, `deferred`, or `disapproved`."""
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
def get_status(self, task, *args, **kwargs):
if 'new_status' in kwargs.keys() or len(args) > 0:
if 'new_status' in kwargs.keys():
new_status = kwargs['new_status']
else:
new_status = args[0]
try:
progress_status = getattr(ProgressStatus, new_status)
except AttributeError as ae:
raise ApiError.from_task(code='invalid_argument',
message=f"We could not find a status matching `{new_status}`. Original message: {ae}",
task=task)
return progress_status.value
raise WorkflowTaskExecException(task, f"set_study_progress_status(). Could not find a status matching"
f" `{new_status}`. Original message: {ae}")
return progress_status
else:
raise ApiError.from_task(code='missing_argument',
message='You must include the new status when calling `set_study_progress_status` script. '
'The new status must be one of `in_progress`, `hold`, `open_for_enrollment`, or `abandoned`.',
task=task)
raise WorkflowTaskExecException(task, f"set_study_progress_status() failed You must include the new"
f" progress status when calling `set_study_progress_status` script.")
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
return self.get_status(task, *args, **kwargs).value
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
# Get new status
if 'new_status' in kwargs.keys() or len(args) > 0:
if 'new_status' in kwargs.keys():
new_status = kwargs['new_status']
else:
new_status = args[0]
# Get ProgressStatus object for new_status
try:
progress_status = getattr(ProgressStatus, new_status)
# Invalid argument
except AttributeError as ae:
raise ApiError.from_task(code='invalid_argument',
message=f"We could not find a status matching `{new_status}`. Original message: {ae}.",
task=task)
# Set new status
study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first()
study_model.progress_status = progress_status
study_model.progress_status = self.get_status(task, *args, **kwargs)
session.commit()
return study_model.progress_status.value
# Missing argument
else:
raise ApiError.from_task(code='missing_argument',
message='You must include the new progress status when calling `set_study_progress_status` script. ',
task=task)

View File

@ -1,4 +1,5 @@
import requests
from SpiffWorkflow.exceptions import WorkflowTaskExecException
from crc import db
from crc.api.common import ApiError
@ -35,8 +36,7 @@ update_study(title=PIComputingID.label, short_title="Really Short Name")
def __update_study(self, task, study, *args, **kwargs):
if len(kwargs.keys()) < 1:
raise ApiError.from_task("missing_argument", self.argument_error_message,
task=task)
raise WorkflowTaskExecException(task, f"update_study() failed. {self.argument_error_message}")
for arg in kwargs.keys():
if arg.lower() == "title":
@ -50,5 +50,4 @@ update_study(title=PIComputingID.label, short_title="Really Short Name")
elif arg.lower() == "pi":
study.primary_investigator_id = kwargs[arg]
else:
raise ApiError.from_task("invalid_argument", self.argument_error_message,
task=task)
raise WorkflowTaskExecException(task, f"update_study() failed. {self.argument_error_message}")

View File

@ -498,10 +498,8 @@ class StudyService(object):
continue
try:
StudyService._create_workflow_model(study_model, workflow_spec)
except WorkflowTaskExecException as wtee:
errors.append(ApiError.from_task("workflow_startup_exception", str(wtee), wtee.task))
except WorkflowException as we:
errors.append(ApiError.from_task_spec("workflow_startup_exception", str(we), we.sender))
errors.append(ApiError.from_workflow_exception("workflow_startup_exception", str(we), we))
return errors
@staticmethod