Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseDocumentRelationships() crash #24

Closed
FleetPhil opened this issue Dec 6, 2018 · 10 comments
Closed

parseDocumentRelationships() crash #24

FleetPhil opened this issue Dec 6, 2018 · 10 comments
Assignees

Comments

@FleetPhil
Copy link

FleetPhil commented Dec 6, 2018

Hi @MaxDesiatov - function was working but I'm now getting a crash on a test sheet, any ideas?

Crash message is: 'try!' expression unexpectedly raised an error: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "relationship", intValue: nil), _XMLKey(stringValue: "Index 3", intValue: 3), CodingKeys(stringValue: "type", intValue: nil)], debugDescription: "Cannot initialize SchemaType from invalid String value http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain", underlyingError: nil))

Spreadsheet is:
Logbook.xlsx

Update: the issue seems to affect any document with formulas, where a calcChain relationship is included in the relationships file

Thanks, Phil

@FleetPhil
Copy link
Author

You just need to add case calcChain = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain" to the SchemaType enum in the Relationship struct...
I would add a pull request and fix it, but it's a bit trivial for that!. Thanks, Phil

@MaxDesiatov
Copy link
Collaborator

Thanks @FleetPhil, would you mind if I add Logbook.xlsx file to the test suite?

@FleetPhil
Copy link
Author

No problem @MaxDesiatov, but I'm now working on another issue on my data, let me try and work out the fix for that and add that to the test sheet. I'm getting a Expected to decode String but found a dictionary instead error on my main sheet, just trying to track it down...

@MaxDesiatov
Copy link
Collaborator

MaxDesiatov commented Dec 7, 2018

Thanks, I'll hold off merging #25 for now until more details and reproducible test cases are available

@FleetPhil
Copy link
Author

FleetPhil commented Dec 7, 2018

I've had a look but I think it's beyond my knowledge of how to decode XML...

The issue is in the SharedStrings file: most entries are as expected by the decoder, for example:

	<si>
		<t>July</t>
	</si>

However some have an additional field, as here:

	<si>
		<t>Annual Total</t>
		<phoneticPr fontId="2" type="noConversion"/>
	</si>

The phoneticPR item makes the decoder think this item is a dictionary and crashes. I amended the SharedStrings definition to create a SimpleText struct with 2 elements to replace the String (similar to the RichText struct), but this crashes on the items without the additional field with the error
Expected to decode Dictionary<String, Any> but found a string/data instead.".
I don't know enough to work out how to handle these 2 cases....

Test sheet attached...
XLSX Test.xlsx

BTW - I'm not actually interested in the phoneticPr value - it just looks like noise and I think could be ignored

Thanks, Phil

@FleetPhil
Copy link
Author

Please also add: case pivotCache = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
to the Relationship struct. Thanks

@MaxDesiatov
Copy link
Collaborator

Thanks @FleetPhil, I've added both cases now in #25. Will address the SharedStrings parsing issue in a separate PR.

MaxDesiatov added a commit that referenced this issue Dec 11, 2018
This addresses parts of #24

* Add `case calcChain` to `Relationship.SchemaType`
* Add `pivotCache` to `Relationships.SchemaType`
@MaxDesiatov
Copy link
Collaborator

The reported cases were aded to the relationships enum, please feel free to reopen the issue if this is still reproducible for you in 0.4.0 and master branch. Thanks.

@mateusgalasso
Copy link

I'm getting almost the same error

Error 2: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "relationship", intValue: nil), XMLKey(stringValue: "2", intValue: 2), CodingKeys(stringValue: "type", intValue: nil)], debugDescription: "Cannot initialize SchemaType from invalid String value http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections", underlyingError: nil))
I tried to put case connections = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections"
but didn't work

@MaxDesiatov
Copy link
Collaborator

Thanks for reporting this @stonkeep, could you please provide more details after checking out the master branch in #56?

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

No branches or pull requests

4 participants