Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Last active September 16, 2019 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JogoShugh/48b1d958c97db22bcb56468030ed25ea to your computer and use it in GitHub Desktop.
Save JogoShugh/48b1d958c97db22bcb56468030ed25ea to your computer and use it in GitHub Desktop.
Bulk Error Handling

The following input payload specifies an array with 9 commands. These nine commands expand to 13 concrete actions for the backend API processor to execute. However, 12 of these actions are erroneous! Only one of them will succeed against the database running on the instance.

[
  {
    "from": "Animal"
  },
  {
    "from": "Scope",
    "where": {
      "NotA": "Real Attribute"
    }
  },
  {
    "from": "Scope",
    "where": {
      "Name": "System (All Projects)"
    },
    "select": [
      "NotAnAttribute"
    ]
  },
  {
    "AssetType": "Epic",
    "Scope": "Scope:9999",
    "Name": "My Epic for a Scope that DOES NOT EXIST which will produce a cascade of four failures!",
    "Subs": [
      {
        "AssetType": "Story",
        "Name": "My Story",
        "Children": [
          {
            "AssetType": "Test",
            "Name": "My Test"
          },
          {
            "AssetType": "Task",
            "Name": "My Task"
          }
        ]
      }
    ]
  },
  {
    "from": "Scope:1003",
    "update": {
      "NotAnAttribute": "Value"
    }
  },
  {
    "from": "Scope:1003",
    "execute": {
      "op": "AssignMemberWithRole",
      "args": {
        "Member": "Member:1234",
        "Role": "Role:9",
        "IsOwner": false
      }
    }
  },
  {
    "from": "Scope:1003",
    "execute": {
      "op": "AssignMemberWithRole",
      "list": [
        {
          "Member": {
            "from": "Member",
            "where": {
              "Username": "scopeListMember1"
            }
          },
          "Role": {
            "from": "Role",
            "where": {
              "Name": "Role.Name'Customer"
            }
          },
          "IsOwner": false
        },
        {
          "Member": "scopeListMember1",
          "Role": {
            "from": "Role",
            "where": {
              "Name": "Role.Name'Customer"
            }
          },
          "IsOwner": false
        }
      ]
    }
  },
  {
    "@user-supplied-alias-without-round-tripped-error-node": {
      "oid": "Scope:1003",
      "update": {
        "NotAnAttribute": "Value"
      }
    }
  },
  {
    "@user-supplied-alias-with-round-tripped-error-node": {
      "oid": "Scope:1003",
      "update": {
        "Descriptionn": {
          "add": [
            "The best project available is this project."
          ],
          "remove": [
            
          ]
        }
      }
    },
	"error": {
		"message": "Unknown AttributeDefinition: Scope.Descriptionn",
		"sourceCommandIndex": 8
	}
  }
]

Preliminary translation step:

[
   {
      "@114b4563-f04b-416b-bf84-aa10f63e8848":{
         "from":"Animals"
      }
   },
   {
      "@cf848f89-484b-436e-a1bb-a5932b4e8b8f":{
         "from":"Scope",
         "where":{
            "NotA":"Real Attribute"
         }
      }
   },
   {
      "@2aa885af-f02d-42a6-b400-1098d4e49a80":{
         "from":"Scope",
         "where":{
            "Name":"System (All Projects)"
         },
         "select":[
            "NotAnAttribute"
         ]
      }
   },
   {
      "@842981c7-2765-4aff-a344-614f40c6261b":{
         "AssetType":"Epic",
         "Scope":"Scope:9999",
         "Name":"My Epic for a Scope that DOES NOT EXIST which will produce a cascade of four failures!"
      }
   },
   {
      "@6e022283-e833-49d1-95fb-95686bb556cb":{
         "AssetType":"Story",
         "Name":"My Story",
         "#ContextOid":"@842981c7-2765-4aff-a344-614f40c6261b"
      }
   },
   {
      "@4d4f95b2-e621-4f6d-9eb1-b5bf26b90df6":{
         "AssetType":"Test",
         "Name":"My Test",
         "#ContextOid":"@6e022283-e833-49d1-95fb-95686bb556cb"
      }
   },
   {
      "@dacdaa2e-fd86-4ac0-985e-281bbd04cdde":{
         "AssetType":"Task",
         "Name":"My Task",
         "#ContextOid":"@6e022283-e833-49d1-95fb-95686bb556cb"
      }
   },
   {
      "@0cc7c26d-6777-44c5-8479-eb78314009c6":{
         "oid":"Scope:1003",
         "update":{
            "NotAnAttribute":{
               "add":[
                  "Value"
               ],
               "remove":[

               ]
            }
         }
      }
   },
   {
      "@d7cff785-df26-4ff6-b6a4-206400ca9093":{
         "oid":"Scope:1003",
         "execute":{
            "op":"AssignMemberWithRole",
            "args":{
               "Member":"Member:1234",
               "Role":"Role:9",
               "IsOwner":"False"
            }
         }
      }
   },
   {
      "@ece4c6b9-e96c-436f-98b3-dc4bf0ae6c6d":{
         "oid":"Scope:1003",
         "execute":{
            "op":"AssignMemberWithRole",
            "args":{
               "Member":"Member:2118",
               "Role":"Role:7",
               "IsOwner":"False"
            }
         }
      }
   },
   {
      "@f701faff-58d8-4f22-8c60-1939e6d0caa0":{
         "oid":"Scope:1003",
         "execute":{
            "op":"AssignMemberWithRole",
            "args":{
               "Member":"scopeListMember1",
               "Role":"Role:7",
               "IsOwner":"False"
            }
         }
      }
   },
   {
      "@user-supplied-alias-without-round-tripped-error-node":{
         "oid":"Scope:1003",
         "update":{
            "NotAnAttribute":"Value"
         }
      }
   },
   {
      "@user-supplied-alias-with-round-tripped-error-node":{
         "oid":"Scope:1003",
         "update":{
            "Descriptionn":{
               "add":[
                  "The best project available is this project."
               ],
               "remove":[

               ]
            }
         }
      }
   },
   {
      "error":{
         "message":"Unknown AttributeDefinition: Scope.Descriptionn",
         "sourceCommandIndex":"8"
      }
   }
]

Execution output, with 12 errors returned to the caller:

{
	"requestId": "cefb2485-618a-4854-96a6-b0340f236fae",
	"createdDate": "2019-09-16T16:25:44.4743104Z",
	"completedDate": "2019-09-16T16:25:44.6103085Z",
	"duration": "00:00:00.1359981",
	"durationSeconds": 0.13599809999999998,
	"complete": true,
	"processing": false,
	"assetsCreated": {
		"oidTokens": [],
		"count": 0
	},
	"assetsModified": {
		"oidTokens": [],
		"count": 0
	},
	"assetsOperatedOn": {
		"oidTokens": [
			"Scope:1003"
		],
		"count": 1
	},
	"commandFailures": {
		"commands": [
			{
				"@35355e65-7507-4550-a0e6-f42ec17fc14e": {
					"from": "Animals"
				},
				"error": {
					"message": "Unknown AssetType: Animals",
					"sourceCommandIndex": 0
				}
			},
			{
				"@eb9bf50e-a2be-4bbc-847a-464e1d539266": {
					"from": "Scope",
					"where": {
						"NotA": "Real Attribute"
					}
				},
				"error": {
					"message": "Invalid QueryFilter2 token NotA='Real Attribute'",
					"sourceCommandIndex": 1
				}
			},
			{
				"@8e252972-a9e5-483e-95f4-68839672ea33": {
					"from": "Scope",
					"where": {
						"Name": "System (All Projects)"
					},
					"select": [
						"NotAnAttribute"
					]
				},
				"error": {
					"message": "Unknown AttributeDefinition: Scope.NotAnAttribute",
					"sourceCommandIndex": 2
				}
			},
			{
				"@f51ffaf6-4e69-48ef-a4e0-bf2ad065ec0b": {
					"AssetType": "Epic",
					"Scope": "Scope:9999",
					"Name": "My Epic for a Scope that DOES NOT EXIST which will produce a cascade of four failures!"
				},
				"error": {
					"message": "Violation'Invalid'Epic.Scope",
					"sourceCommandIndex": 3
				}
			},
			{
				"@a9a052ff-7f48-411c-8f6e-4c79577bdecc": {
					"AssetType": "Story",
					"Name": "My Story",
					"#ContextOid": "@f51ffaf6-4e69-48ef-a4e0-bf2ad065ec0b"
				},
				"error": {
					"message": "Invalid OID token: @f51ffaf6-4e69-48ef-a4e0-bf2ad065ec0b",
					"sourceCommandIndex": 3
				}
			},
			{
				"@6315ef5e-9923-40ba-9b2c-6c50d0d19b51": {
					"AssetType": "Test",
					"Name": "My Test",
					"#ContextOid": "@a9a052ff-7f48-411c-8f6e-4c79577bdecc"
				},
				"error": {
					"message": "Invalid OID token: @a9a052ff-7f48-411c-8f6e-4c79577bdecc",
					"sourceCommandIndex": 3
				}
			},
			{
				"@fd472927-09c2-4a38-a7f7-f4b112997066": {
					"AssetType": "Task",
					"Name": "My Task",
					"#ContextOid": "@a9a052ff-7f48-411c-8f6e-4c79577bdecc"
				},
				"error": {
					"message": "Invalid OID token: @a9a052ff-7f48-411c-8f6e-4c79577bdecc",
					"sourceCommandIndex": 3
				}
			},
			{
				"@16edc4e8-758d-4819-83d0-7361eed86a4b": {
					"oid": "Scope:1003",
					"update": {
						"NotAnAttribute": {
							"add": [
								"Value"
							],
							"remove": []
						}
					}
				},
				"error": {
					"message": "Unknown AttributeDefinition: Scope.NotAnAttribute",
					"sourceCommandIndex": 4
				}
			},
			{
				"@2752458e-058c-402e-8b79-a45b413e4630": {
					"oid": "Scope:1003",
					"execute": {
						"op": "AssignMemberWithRole",
						"args": {
							"Member": "Member:1234",
							"Role": "Role:9",
							"IsOwner": "False"
						}
					}
				},
				"error": {
					"message": "The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_ScopeMemberACL_MemberID\". The conflict occurred in database \"V1Web\", table \"dbo.Member_Now\", column 'ID'.\r\nThe statement has been terminated.",
					"sourceCommandIndex": 5
				}
			},
			{
				"@7277f466-1863-456c-948b-4591fc21a3f4": {
					"oid": "Scope:1003",
					"execute": {
						"op": "AssignMemberWithRole",
						"args": {
							"Member": "scopeListMember1",
							"Role": "Role:7",
							"IsOwner": "False"
						}
					}
				},
				"error": {
					"message": "Invalid OID token: scopeListMember1",
					"sourceCommandIndex": 6
				}
			},
			{
				"@user-supplied-alias-without-round-tripped-error-node": {
					"oid": "Scope:1003",
					"update": {
						"NotAnAttribute": "Value"
					}
				},
				"error": {
					"message": "Unknown AttributeDefinition: Scope.NotAnAttribute",
					"sourceCommandIndex": 7
				}
			},
			{
				"@user-supplied-alias-with-round-tripped-error-node": {
					"oid": "Scope:1003",
					"update": {
						"Descriptionn": {
							"add": [
								"The best project available is this project."
							],
							"remove": []
						}
					}
				},
				"error": {
					"message": "Unknown AttributeDefinition: Scope.Descriptionn",
					"sourceCommandIndex": 8
				}
			}
		],
		"count": 12
	},
	"queryResult": {
		"results": [],
		"count": -1
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment