Skip to content

Conversation

@RCCoop
Copy link

@RCCoop RCCoop commented Nov 10, 2025

Seeking out errors from AEXMLElement.error always seemed unintuitive to me, where throwing functions are the more idiomatic Swift way to handle this. So here is a pull request that removes the error property, and instead makes the places where existing errors could be created into throwing functions.

This is a breaking change, of course, since it changes the call signature of the following:

  • AEXMLDocument.root Getter now throws AEXMLError.rootElementMissing if no root element exists (previously, this would return an empty AEXMLElement with the error stored in its error property).
  • AEXMLElement["key"] getter now throws AEXMLError.elementNotFound(String)` if the element with the given name is not found (previously, this would also return an empty element with an error property).

Extra changes I made:

  • Updated Unit Tests to Swift Testing
  • AEXMLError.elementNotFound now includes the key that wasn't found, so you can chain subscripts together and know which one failed, like so:
// this throws AEXMLError.elementNotFound("badKey1")
let x = try element["goodKey"]["badKey1"]["badKey2"]

Hope you like it. Thanks for creating this library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant