Skip to content

Fix crash when running Lint from LegacyMain #267

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

Closed
wants to merge 1 commit into from

Conversation

mtgto
Copy link

@mtgto mtgto commented Sep 25, 2021

Fix crash bug in LegacyMain lint mode. I test with Xcode 13 and tag 0.50500.0 on macOS 11.6 Intel.
This crash does not happen in using SubCommand lint.

In addition, adds a description of strict flag to README.

$ swift run swift-format --mode lint Package.swift
[0/0] Build complete!
/Users/user/work/cocoa/swift-format/Package.swift:15:1: warning: [OrderedImports]: sort import statements lexicographically
/Users/user/work/cocoa/swift-format/Package.swift:83:22: warning: remove trailing comma from the last element in single line collection literal
/Users/user/work/cocoa/swift-format/Package.swift:24:18: warning: [RemoveLine]: remove line break
/Users/user/work/cocoa/swift-format/Package.swift:140:2: warning: [RemoveLine]: remove line break
/Users/user/work/cocoa/swift-format/Package.swift:147:1: warning: [LineLength]: line is too long
ArgumentParser/Flag.swift:103: Fatal error:
--------------------------------------------------------------------
Can't read a value from a parsable argument definition.

This error indicates that a property declared with an `@Argument`,
`@Option`, `@Flag`, or `@OptionGroup` property wrapper was neither
initialized to a value nor decoded from command-line arguments.

To get a valid value, either call one of the static parsing methods
(`parse`, `parseAsRoot`, or `main`) or define an initializer that
initializes _every_ property of your parsable type.
--------------------------------------------------------------------

zsh: illegal hardware instruction  swift run swift-format --mode lint Package.swift

#252 introduces --strict, but this flag should be defined in LintFormatOptions.swift, not Lint.swift.

@kylebrowning
Copy link

Test this and it fixed it. Also couldn't find a way to run --strict prior to this PR.

@mtgto
Copy link
Author

mtgto commented Oct 20, 2021

Test this and it fixed it.

Hmm, it does not fixed in my environment.
I test at main branch.

$ git rev-parse head
848395f6ba858304f44081d75114ec8506a720d7

$ SWIFTCI_USE_LOCAL_DEPS=1 swift build
dylib (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib) was built

ld: warning: dylib (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib) was built for newer macOS version (10.14.6) than being linked (10.10)
[193/193] Build complete!

$ .build/x86_64-apple-macosx/debug/swift-format --mode lint Package.swift
/Users/user/work/cocoa/swift-format/Package.swift:15:1: warning: [OrderedImports]: sort import statements lexicographically
/Users/user/work/cocoa/swift-format/Package.swift:83:22: warning: remove trailing comma from the last element in single line collection literal
/Users/user/work/cocoa/swift-format/Package.swift:24:18: warning: [RemoveLine]: remove line break
/Users/user/work/cocoa/swift-format/Package.swift:140:2: warning: [RemoveLine]: remove line break
ArgumentParser/Flag.swift:103: Fatal error:
--------------------------------------------------------------------
Can't read a value from a parsable argument definition.

This error indicates that a property declared with an `@Argument`,
`@Option`, `@Flag`, or `@OptionGroup` property wrapper was neither
initialized to a value nor decoded from command-line arguments.

To get a valid value, either call one of the static parsing methods
(`parse`, `parseAsRoot`, or `main`) or define an initializer that
initializes _every_ property of your parsable type.
--------------------------------------------------------------------

zsh: illegal hardware instruction  .build/x86_64-apple-macosx/debug/swift-format --mode lint Package.swift

$ echo $?
132

it does not crash while using subcommand mode:

$ .build/x86_64-apple-macosx/debug/swift-format lint Package.swift
/Users/user/work/cocoa/swift-format/Package.swift:15:1: warning: [OrderedImports]: sort import statements lexicographically
/Users/user/work/cocoa/swift-format/Package.swift:83:22: warning: remove trailing comma from the last element in single line collection literal
/Users/user/work/cocoa/swift-format/Package.swift:24:18: warning: [RemoveLine]: remove line break
/Users/user/work/cocoa/swift-format/Package.swift:140:2: warning: [RemoveLine]: remove line break

$ echo $?
0

Also couldn't find a way to run --strict prior to this PR.

strict flag can be used only non-legacy mode (subcommand mode).

$ swift-format --version
0.50500.0

$ swift-format lint --strict Package.swift
/Users/user/work/cocoa/swift-format/Package.swift:15:1: warning: [OrderedImports]: sort import statements lexicographically
/Users/user/work/cocoa/swift-format/Package.swift:83:22: warning: remove trailing comma from the last element in single line collection literal
/Users/user/work/cocoa/swift-format/Package.swift:24:18: warning: [RemoveLine]: remove line break
/Users/user/work/cocoa/swift-format/Package.swift:140:2: warning: [RemoveLine]: remove line break

$ echo $?
1

$ swift-format lint Package.swift
/Users/user/work/cocoa/swift-format/Package.swift:15:1: warning: [OrderedImports]: sort import statements lexicographically
/Users/user/work/cocoa/swift-format/Package.swift:83:22: warning: remove trailing comma from the last element in single line collection literal
/Users/user/work/cocoa/swift-format/Package.swift:24:18: warning: [RemoveLine]: remove line break
/Users/user/work/cocoa/swift-format/Package.swift:140:2: warning: [RemoveLine]: remove line break

$ echo $?
0

@kylebrowning
Copy link

I meant to say I tested your PR and it didn't crash

@mtgto
Copy link
Author

mtgto commented Oct 21, 2021

😄

@allevato
Copy link
Member

allevato commented Nov 4, 2021

Since this only happens with the legacy --mode flag, we should just remove that entirely (I've been meaning to anyway, but it's never bubbled up in my priority list). There's no compelling reason to keep the legacy mode anymore—it was only provided for users to transition to the subcommand syntax, which they've had plenty of time to do.

@allevato
Copy link
Member

The legacy entry point and --mode flag were removed in #275, so AFAICT this is no longer needed. (Please re-open if that isn't the case!)

Thanks for bringing it up regardless—it was the motivation I needed to kick out the old compatibility mode. 🙂

@allevato allevato closed this Nov 13, 2021
@mtgto
Copy link
Author

mtgto commented Nov 13, 2021

@allevato

The legacy entry point and --mode flag were removed in #275, so AFAICT this is no longer needed. (Please re-open if that isn't the case!)

README.md has description about options --mode, and lack of --strict.
Can you fix it? (I will not create a PR to fix it)

@mtgto mtgto deleted the fix_legacy_main_strict_flag branch November 13, 2021 01:20
@allevato
Copy link
Member

Thanks for the reminder! #276 updates the docs.

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.

3 participants