tsabend / fus

Find unused Swift classes
MIT License
319 stars 14 forks source link

invalid byte sequence in UTF-8 #24

Open petaren opened 6 years ago

petaren commented 6 years ago

I installed fus using sudo gem install fus and tried running it in the root of my project but got the following error message:

$ fus find
/Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/swift_class.rb:26:in `match': invalid byte sequence in UTF-8 (ArgumentError)
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/swift_class.rb:26:in `match'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/swift_class.rb:26:in `used_in_obj_c?'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/finder.rb:69:in `block in used_in_obj_c?'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/finder.rb:69:in `any?'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/finder.rb:69:in `used_in_obj_c?'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/finder.rb:48:in `block in unused_classes'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/finder.rb:44:in `reject'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/finder.rb:44:in `unused_classes'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/lib/fus/finder.rb:21:in `unused_classnames'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/bin/fus:14:in `find'
    from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
    from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    from /Library/Ruby/Gems/2.3.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
    from /Library/Ruby/Gems/2.3.0/gems/fus-0.0.3/bin/fus:34:in `<top (required)>'
    from /usr/local/bin/fus:22:in `load'
    from /usr/local/bin/fus:22:in `<main>'
tsabend commented 6 years ago

Weird. You must have some character that the regex function doesn't like in one of your source files. I'd need to have more info about the specifics to fix

oleghnidets commented 6 years ago

I have the same issue.

tsabend commented 6 years ago

@oleghnidets if there is any way you can provide a test file that causes this failure that would be helpful.

krin-san commented 5 years ago

While debugging, I noticed fus goes very deeply into the Pods folder analyzing if swift class is used in ObjC classes and failed on this file:

.../Pods/Postal/dependencies/build/macos/include/libetpan/clist.h

This file online: https://github.com/dinhviethoa/libetpan/blob/master/src/data-types/clist.h

The file which was analyzing by fus at the moment of failure is just the first available file containing that:

//
//  EmptyCase.swift
//  

import XCTest

/// Empty test case to make Tests target compilable until any platform-specific tests would be added
class EmptyCase: XCTestCase {}

Workaround for me was: