This repository was archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
This repository was archived by the owner on Nov 1, 2023. It is now read-only.
Wrap fallible ORM functions in Try/Catch #2709
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Some ORM operations are fallible. We have existing code that attempts to handle the failure modes using .IsError but it turns out that they can also throw exceptions. Here's an example:
onefuzz/src/ApiService/ApiService/onefuzzlib/orm/Orm.cs
Lines 81 to 92 in 349604f
| public async Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Replace(T entity) { | |
| var tableClient = await GetTableClient(typeof(T).Name); | |
| var tableEntity = _entityConverter.ToTableEntity(entity); | |
| var response = await tableClient.UpsertEntityAsync(tableEntity, TableUpdateMode.Replace); | |
| if (response.IsError) { | |
| return ResultVoid<(HttpStatusCode, string)>.Error(((HttpStatusCode)response.Status, response.ReasonPhrase)); | |
| } else { | |
| // update ETag on success | |
| entity.ETag = response.Headers.ETag; | |
| return ResultVoid<(HttpStatusCode, string)>.Ok(); | |
| } | |
| } |
That example can also throw Azure.RequestFailedException.
Feature request
For all fallible ORM functions, wrap them in try/catch and return the appropriate OneFuzzResult type.
AB#42650423
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request