IBDecodable / IBLinter

A linter tool for Interface Builder
MIT License
950 stars 40 forks source link

Crash while trying to parse WatchKit app storyboard #104

Closed mgrebenets closed 5 years ago

mgrebenets commented 5 years ago

Hi there

We've got one WatchKit app storyboard, that seems to cause trouble for IBLinter and causes it to crash.

The error is this:

Fatal error: parse error /path/to/project/WatchKitApp/Base.lproj/Interface.storyboard: XML Element Error: Incorrect key ["archive"]: file /Users/travis/build/IBDecodable/IBLinter/Sources/IBLinterKit/Validator.swift, line 36

The storyboard renders in Xcode properly, I've checked it with xmllint and it reported no errors. I can't even find a key called "archived" inside storyboard XML file 🤔

not sure what's the root cause.

Out of curiosity, I've removed everything from the storyboard and only this was left:

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14460.31" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">

</document>

still causes the same crash.

phimage commented 5 years ago

watch os are not supported but must be skipped the expected error thrown by IBDecodable https://github.com/IBDecodable/IBDecodable/blob/e9b642b6e8e1dc77ae9f139286197cd5bde754f0/Sources/Parsers/InterfaceBuilderParser.swift#L74

the decoding https://github.com/IBDecodable/IBDecodable/blob/e9b642b6e8e1dc77ae9f139286197cd5bde754f0/Sources/Parsers/InterfaceBuilderParser.swift#L23

mgrebenets commented 5 years ago

I see, so all IBLinter users should ignore WatchKit storyboards then...

Just curious, instead of crashing, could IBLinter display a warning saying "WatchKit storyboards are not supported" or just skip them silently? I guess any kind of warning would be better than the crash.

I've spend some time digging into our WatchKit storyboard trying to understand where exactly it is broken.

phimage commented 5 years ago

the issue is for any malformed xml as I see (like empty one from test)

We receive a not converted/catched IndexingError from XML decoding library XML Element Error: Incorrect key ["archive"]

error thrown by https://github.com/IBDecodable/IBDecodable/blob/e9b642b6e8e1dc77ae9f139286197cd5bde754f0/Sources/Parsers/InterfaceBuilderParser.swift#L67

solution: Upgrade IBDecodable dependencies, update to swift 5 Add a new error case Error.indexingError(IndexingError), manage it catch IndexingError at previous mentioned line to create Error.indexingError

mgrebenets commented 5 years ago

The XML in question is WatchKit storyboard. I couldn’t paste the full version. Will try to create fresh WatchKit storyboard instead and see if it still causes same issue.

Other than that the XML that I have renders properly in interface builder and lints fine with xmllint tool.

phimage commented 5 years ago

I make I think the necessary change in IBDecodable project

A violation must be created from Error.xmlError and no more fatalError when new version of IBDecodable will be integrated here

mgrebenets commented 5 years ago

Tested just now, I get the warning now

... warning: Parse XML error XML Element Error: Incorrect key ["archive"]

Which is much better than a crash from before đź‘Ť