The OpenXmlPartContainer.DeletePart will throw exception when the id not found
See original GitHub issueBefore submitting an issue, please fill this out
Is this a:
- Issue with the OpenXml library
- Question on library usage
Description
As we can see the OpenXmlPartContainer.DeletePart can delete the part, but this API will throw ArgumentOutOfRangeException when the part with the specified id does not exist.
Because the DeletePart
call the DeletePartCore
which will call the GetPartById
to get the part.
But the GetPartById
will throw ArgumentOutOfRangeException when the part with the specified id does not exist.
Yes, it means that the branch will never enter when the id not found
Information
- .NET Target: All
- DocumentFormat.OpenXml Version: 2.10.1
Repro
public static void Delete(this string id, OpenXmlPart part)
{
part.DeletePart(id);
}
Observed
The part.DeletePart
will throw the exception when the part with the specified id does not exist.
Expected
As the other API design, the delete method should not throw exception the element does not exist.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
The OpenXmlPartContainer.DeletePart will throw ...
DeletePart can delete the part, but this API will throw ArgumentOutOfRangeException when the part with the specified id does not exist.
Read more >OpenXmlPartContainer.DeletePart Method
This method also returns false if the part was not found. Exceptions. ArgumentNullException. Thrown when "id" is null reference. Applies to. DocumentFormat.
Read more >How to I tell a Springdata-repository's delete method to not ...
We should not throw not found exception when the id not found, since there maybe a cheat to check whether this ID exists...
Read more >16 Handling Exceptions Using SOAP Faults
This chapter describes how to handle exceptions that occur when a message is being processed using Simple Object Access Protocol (SOAP) faults for...
Read more >Should a function throw exceptions based on its expected ...
To try to delete a post with an invalid postId does not make sense, so an exception should be thrown. My colleague argues...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@twsouthwick I’d be interested in picking this up, seems like a straight forward change to start with
@twsouthwick After https://github.com/OfficeDev/Open-XML-SDK/pull/714 merged, we can use this API to check whether the OpenXmlPartContainer contain the part with the specified id. So, there are ways to avoid this problem.