rockbruno / SwiftInfo

📊 Extract and analyze the evolution of an iOS app's code.
https://swiftrocks.com
MIT License
1.15k stars 58 forks source link

v2.3.14 is crashing: "The file “swiftinfo” couldn’t be opened because there is no such file." #56

Open rogerluan opened 3 years ago

rogerluan commented 3 years ago

Hey 👋

After the latest release https://github.com/rockbruno/SwiftInfo/releases/tag/2.3.14 I couldn't get SwiftInfo to work.

On CI it triggers weird and misleading errors (e.g. Error: Unknown option '-u', although I'm not passing any -u option). On my local machine, attempting to run the same command than CI (swiftinfo -release) I'm getting this:

Error: Unknown option '-r'
Usage: swiftinfo [--help] [--silent] [--verbose] [--print-sourcekit] [<arguments> ...]
  See 'swiftinfo --help' for more information.

I believe this has to do with the major refactor that happened here: https://github.com/rockbruno/SwiftInfo/pull/54

Attempting to run swiftinfo -version would work before. Now it throws:

Error: Unknown option '-e'

I'm assuming we should all forcefully adhere to the new API, so then this should work: swiftinfo --version, but:

Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file “swiftinfo” couldn’t be opened because there is no such file." UserInfo={NSURL=swiftinfo -- file:///Users/rogerluan/Documents/Projects/redacted/, NSFilePath=/Users/rogerluan/Documents/Projects/redacted/swiftinfo, NSUnderlyingError=0x7fd9a4b04830 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}: file SwiftInfoCore/FileUtils.swift, line 39
[1]    76589 illegal hardware instruction  swiftinfo --version

I noticed that amongst other things, that PR changed instances of ProcessInfo.processInfo.arguments with CommandLine.arguments and those are not interchangeable. See:

#!/usr/bin/swift

import Foundation

print("ProcessInfo.processInfo.arguments.first = ", ProcessInfo.processInfo.arguments.first!)
print("CommandLine.arguments.first = ", CommandLine.arguments.first!)
print("FileManager.default.currentDirectoryPath = ", FileManager.default.currentDirectoryPath)

Outputs:

ProcessInfo.processInfo.arguments.first =  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
CommandLine.arguments.first =  ./_test.swift
FileManager.default.currentDirectoryPath =  /Users/rogerluan/Documents/Projects/SwiftInfo

So that may be the root cause of the issue, but even after fixing that, I couldn't have it find my Infofile.swift anymore. At this point I'm just gonna rollback to the previous release that is stable and freeze it there for awhile 😞


Quick feedback

The last release should've been a major bump IMO, since it broke existing APIs (it was not backwards compatible). Moreover, looks like it wasn't well tested before being released 😬 I'm just leaving a constructive feedback here 🙈 🤗 We currently use this in production, so stability is important 🙏

Appreciate all the hard work towards this great tool! 🚀

rockbruno commented 3 years ago

What's going on in your CI that CommandLine.arguments returns /_test.swift? These are supposed to be the launch arguments of the tool, but we don't have arguments that take files 🤔 I assume the way you are calling it is what is causing it to pass our tests and not your CI.

There was one more place in that PR that changed the processinfo stuff, I think changing those two parts should fix it.

rogerluan commented 3 years ago

Our CI calls it like this: swiftinfo only (there's another place that invokes swiftinfo -release but we don't even have to call that for it to crash) The test.swift was a .swift script I wrote to test those 3 different paths/arguments 🙈

Your suggestion might work, I just haven't had the opportunity to test it

rockbruno commented 3 years ago

I would guess that there's something in the environment (or if you call it from a swift script) that adds more launch arguments, and then the logic of getting the script folder gets screwed up. Obviously that is a dumb excuse so we should just change it to what it was before 😛 But this is quite unexpected, I didn't know CommandLine behaved like this.

rockbruno commented 3 years ago

I made the changes to revert it, but your Error: Unknown option '-r' errors are something else. We are using an special option in the argument parser to allow "custom arguments" and it works fine when called from the terminal/makefile, so there's something else in your case causing this

rockbruno commented 3 years ago

Aaaactually, I found out the problem. The argument parser's custom arguments only work if you follow the right naming scheme (- for letters and -- for everything else). Your CI is failing because your argument needs to be --release, not -release. I updated the docs to reflect that now.

rogerluan commented 3 years ago

I tested it and it seems to work (as of current master) 👍 nice find @rockbruno ! 💪

rogerluan commented 3 years ago

Feel free to close this issue once a new release is submitted 😊