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

Fails on Xcode 12 #365

Closed
ecerney opened this issue Aug 28, 2020 · 35 comments
Closed

Fails on Xcode 12 #365

ecerney opened this issue Aug 28, 2020 · 35 comments

Comments

@ecerney
Copy link

ecerney commented Aug 28, 2020

I'm still trying to debug why exactly it's failing, but thought I'd post the issue here while I look into it in case someone else has seen the same thing.

Issue:
Since switching to Xcode-12 beta, danger stopped working on bitrise (and locally). The command I'm running locally is:

swift run --package-path scripts/swift/Danger/ --build-path .build danger-swift pr {GITHUB_PR_URL} --dangerfile scripts/swift/Danger/DangerFilePreChecks.swift --verbose

And the result is:

Launching Danger Swift pr (v3.4.1)
Finding out where the danger executable is
Running: /usr/local/bin/danger pr --process .build/debug/danger-swift --passURLForDSL {GITHUB_PR_URL} --dangerfile scripts/swift/Danger/DangerFilePreChecks.swift --verbose --id PreChecks
Starting Danger PR on {GITHUB_PR_URL}
0  swift                    0x000000011170aa85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37

1  swift                    0x0000000111709a85 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000011170b03f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6d3625fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338683898400

5  libswiftCore.dylib       0x00007fff6c911c0c $ss21__SharedStringStorageC13getCharacters_5rangeySpys6UInt16VG_So13_SwiftNSRangeatF + 172
6  libswiftCore.dylib       0x00007fff6c911d28
$ss21__SharedStringStorageC13getCharacters_5rangeySpys6UInt16VG_So13_SwiftNSRangeatFTo + 24
7  CoreFoundation           0x00007fff330a4a71 __CFStringEncodeByteStream + 1857
8  Foundation               0x00007fff35742268 -[NSString(NSStringOtherEncodings) lengthOfBytesUsingEncoding:] + 103

9  Foundation               0x00007fff3579f1aa -[NSPlaceholderString initWithString:] + 159
10 libswiftFoundation.dylib 0x00007fff6cc54886 $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLV6encode_6forKeyySS_xtKF + 3430
11 libswiftFoundation.dylib 0x00007fff6cc5cf0e $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLVyxGs05KeyedcD8ProtocolAAsAFP6encode_6forKeyySS_0P0QztKFTW + 14

12 libswiftCore.dylib       0x00007fff6c981234 $ss26_KeyedEncodingContainerBoxC6encode_6forKeyySS_0G0QztKF + 36

13 libswiftCore.dylib       0x00007fff6c97afa5 $ss22KeyedEncodingContainerV6encode_6forKeyySS_xtKF + 69
14 libDanger.dylib          0x0000000116c0801c $s6Danger9ViolationV6encode2toys7Encoder_p_tKF + 300
15
 libDanger.dylib          0x0000000116c082a2 $s6Danger9ViolationVSEAASE6encode2toys7Encoder_p_tKFTW + 66
16 libswiftCore.dylib       0x00007fff6ca67367 $sSE6encode2toys7Encoder_p_tKFTj + 7

17 libswiftFoundation.dylib 0x00007fff6cc4bac2 $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 4178
18 libswiftFoundation.dylib 0x00007fff6cc5ecef $s10Foundation29_JSONUnkeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLV6encodeyyxKSERzlF + 703
19 libswiftFoundation.dylib 0x00007fff6cc60049 $s10Foundation29_JSONUnkeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLVs07UnkeyedcD0AAsAEP6encodeyyqd__KSERd__lFTW + 9

20 libswiftCore.dylib       0x00007fff6c98a914 $sSasSERzlE6encode2toys7Encoder_p_tKF + 660

21 libswiftCore.dylib       0x00007fff6c98aa68 $sSayxGSEsSERzlSE6encode2toys7Encoder_p_tKFTW + 24

22 libswiftCore.dylib       0x00007fff6ca67367 $sSE6encode2toys7Encoder_p_tKFTj + 7
23 libswiftFoundation.dylib 0x00007fff6cc4bac2 $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 4178
24 libswiftFoundation.dylib 0x00007fff6cc5890f $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLV6encode_6forKeyyqd___xtKSERd__lF + 3791
25 libswiftFoundation.dylib 0x00007fff6cc5d095 $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLVyxGs05KeyedcD8ProtocolAAsAFP6encode_6forKeyyqd___0P0QztKSERd__lFTW + 21

26 libswiftCore.dylib       0x00007fff6c9814a7 $ss26_KeyedEncodingContainerBoxC6encode_6forKeyyqd___0G0QztKSERd__lF + 39

27 libswiftCore.dylib       0x00007fff6c93f3ac $ss22KeyedEncodingContainerV6encode_6forKeyyqd___xtKSERd__lF + 76
28 libDanger.dylib          0x0000000116c09ee0 $s6Danger0A7ResultsV6encode2toys7Encoder_p_tKF + 704

29 libDanger.dylib          0x0000000116c0a523 $s6Danger0A7ResultsVSEAASE6encode2toys7Encoder_p_tKFTW + 83

30 libswiftCore.dylib       0x00007fff6ca67367 $sSE6encode2toys7Encoder_p_tKFTj + 7
31 libswiftFoundation.dylib 0x00007fff6cc4bac2 $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 4178

32 libswiftFoundation.dylib 0x00007fff6cc4a628 $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlF + 456
33 libswiftFoundation.dylib 0x00007fff6cd3cede $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlFTj + 14

34 libDanger.dylib          0x0000000116bac867 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyF + 1303
35 libDanger.dylib          0x0000000116bad429 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyFTo + 9
36 libsystem_c.dylib        0x00007fff6d213143
 __cxa_finalize_ranges + 326
37 libsystem_c.dylib        0x00007fff6d213412 exit + 55
38 libdyld.dylib            0x00007fff6d169cd0 start + 8
39 libdyld.dylib            0x000000000000001d start + 18446603338685965141



Launching Danger Swift runner (v3.4.1)
Got URL for JSON: /var/folders/fn/gwhkhbj526b_qlrl0sm8jhnxtnzk2_/T/danger-dsl.json
Created a temporary file for the Dangerfile DSL at: /var/folders/fn/gwhkhbj526b_qlrl0sm8jhnxtnzk2_/T/danger-dsl.json
Running Dangerfile at: scripts/swift/Danger/DangerFilePreChecks.swift
Preparing to compile
Running: /Users/ecerney/.swiftenv/shims/swiftc --driver-mode=swift -L /Users/ecerney/ios/project/.build/debug -I /Users/ecerney/ios/project/.build/debug -lDanger /var/folders/fn/gwhkhbj526b_qlrl0sm8jhnxtnzk2_/T/_tmp_dangerfile.swift runner /snapshot/danger-js/distribution/commands/danger-pr.js --process .build/debug/danger-swift --passURLForDSL {GITHUB_PR_URL} --dangerfile scripts/swift/Danger/DangerFilePreChecks.swift --verbose --id PreChecks /var/folders/fn/gwhkhbj526b_qlrl0sm8jhnxtnzk2_/T/danger-dsl.json /var/folders/fn/gwhkhbj526b_qlrl0sm8jhnxtnzk2_/T/danger-response.json
Completed evaluation
ERROR: Dangerfile eval failed at scripts/swift/Danger/DangerFilePreChecks.swift
Saving and storing the results at /var/folders/fn/gwhkhbj526b_qlrl0sm8jhnxtnzk2_/T/danger-response.json

This issue does not happen if I change the toolchain back to Xcode 11.

@f-meloni
Copy link
Member

Interesting, will try it on Xcode 12 and see if I can get something useful

@f-meloni
Copy link
Member

I tried with the Dangerfile in this repo and got

swift run danger-swift pr https://github.com/danger/swift/pull/314 --dangerfile Dangerfile.swift
[4/4] Merging module Logger
Starting Danger PR on danger/swift#314
You don't have a DANGER_GITHUB_API_TOKEN set up, this is optional, but TBH, you want to do this
Check out: http://danger.systems/js/guides/the_dangerfile.html#working-on-your-dangerfile


Danger: ✓ passed review, received no feedback.

I also tried with a test warning

➜  swift git:(master) ✗ swift run danger-swift pr https://github.com/danger/swift/pull/314 --dangerfile Dangerfile.swift
[4/4] Merging module Logger
Starting Danger PR on danger/swift#314
You don't have a DANGER_GITHUB_API_TOKEN set up, this is optional, but TBH, you want to do this
Check out: http://danger.systems/js/guides/the_dangerfile.html#working-on-your-dangerfile


Danger: ✓ found only warnings, not failing the build
## Warnings
Test

Looking at the stacktrace you posted

28 libDanger.dylib          0x0000000116c09ee0 $s6Danger0A7ResultsV6encode2toys7Encoder_p_tKF + 704

29 libDanger.dylib          0x0000000116c0a523 $s6Danger0A7ResultsVSEAASE6encode2toys7Encoder_p_tKFTW + 83

30 libswiftCore.dylib       0x00007fff6ca67367 $sSE6encode2toys7Encoder_p_tKFTj + 7
31 libswiftFoundation.dylib 0x00007fff6cc4bac2 $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 4178

32 libswiftFoundation.dylib 0x00007fff6cc4a628 $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlF + 456
33 libswiftFoundation.dylib 0x00007fff6cd3cede $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlFTj + 14

34 libDanger.dylib          0x0000000116bac867 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyF + 1303
35 libDanger.dylib          0x0000000116bad429 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyFTo + 9

Makes me think that there might be some string in the warnings, messages, markdowns or failures that might be making it crash for some reason when is encoded in the JSON file that is returned as result of the Dangerfile execution

@ecerney
Copy link
Author

ecerney commented Aug 28, 2020

Hmm interesting @f-meloni... I've completely cleared out the dangerfile though with only a single message with normal text and still have the same issue... Let me try running danger as you did on this repo and see what happens

@ecerney
Copy link
Author

ecerney commented Aug 28, 2020

@f-meloni I was able to successfully do it from this repo like you were... and I was able to reproduce the crash on the repo as well. This is really strange but the difference in one letter of a message will crash. Here are two examples of a Dangerfile:

Succeeds:

import Danger
import Foundation

let danger = Danger()

message("Testing just a ")

Fails:

import Danger
import Foundation

let danger = Danger()

message("Testing just a m")

The only difference is the "m" in the message... how could this be crashing it? Maybe related to the length of the string?

@ecerney
Copy link
Author

ecerney commented Aug 28, 2020

From what I can gather... any string over 15 characters long crashes! message("123456789012345") works, but message("1234567890123456") doesn't

@f-meloni
Copy link
Member

Mmmmm

0  swift                    0x000000011170aa85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37

1  swift                    0x0000000111709a85 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000011170b03f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6d3625fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338683898400

5  libswiftCore.dylib       0x00007fff6c911c0c $ss21__SharedStringStorageC13getCharacters_5rangeySpys6UInt16VG_So13_SwiftNSRangeatF + 172
6  libswiftCore.dylib       0x00007fff6c911d28
$ss21__SharedStringStorageC13getCharacters_5rangeySpys6UInt16VG_So13_SwiftNSRangeatFTo + 24
7  CoreFoundation           0x00007fff330a4a71 __CFStringEncodeByteStream + 1857
8  Foundation               0x00007fff35742268 -[NSString(NSStringOtherEncodings) lengthOfBytesUsingEncoding:] + 103

9  Foundation               0x00007fff3579f1aa -[NSPlaceholderString initWithString:] + 159
10 libswiftFoundation.dylib 0x00007fff6cc54886 $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLV6encode_6forKeyySS_xtKF + 3430
11 libswiftFoundation.dylib 0x00007fff6cc5cf0e $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLVyxGs05KeyedcD8ProtocolAAsAFP6encode_6forKeyySS_0P0QztKFTW + 14

12 libswiftCore.dylib       0x00007fff6c981234 $ss26_KeyedEncodingContainerBoxC6encode_6forKeyySS_0G0QztKF + 36

The only thing I see here is that it tried to encode the violation message and then crashes, it might be a bug in the JSONEncoder, in NSString or in NSPlaceholderString.

@f-meloni
Copy link
Member

warn("Test 12345678901") instead of crashing gives me an empty string 🤔
But I don't have the latest beta

[4/4] Merging module Logger
Starting Danger PR on danger/swift#314
You don't have a DANGER_GITHUB_API_TOKEN set up, this is optional, but TBH, you want to do this
Check out: http://danger.systems/js/guides/the_dangerfile.html#working-on-your-dangerfile


Danger: ✓ found only warnings, not failing the build
## Warnings


@ecerney
Copy link
Author

ecerney commented Aug 28, 2020

The same string you just posted crashes for me (Xcode-beta 6). So ya... could be a bug with encoding or something, but that seems like it would be a much bigger issue in the betas since we use features like that all over the place in our apps.

@ecerney
Copy link
Author

ecerney commented Aug 28, 2020

So it seems it's not directly related to messaging, since the following also crashes:

import Danger
import Foundation

enum Foo {
    case bar
}

let danger = Danger()
message("Hey")

Seems like an issue parsing the Dangerfile in general. Removing the enum works fine.

@f-meloni
Copy link
Member

Does the enum crash have the same stacktrace?

@ecerney
Copy link
Author

ecerney commented Aug 28, 2020

Looks like a different stacktrace (but similar starts).

Enum Stacktrace:

0  swift                    0x000000011364ca85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000011364ba85 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000011364d03f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6d3625fd _sigtramp + 29
4  libsystem_platform.dylib 0x0000000115896a00 _sigtramp + 18446603343340192800
5  libswiftCore.dylib       0x00007fff6caae946 swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 86
6  libswiftCore.dylib       0x00007fff6ca7d5ea swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**) + 42
7  libswiftCore.dylib       0x00007fff6ca812cb _conformsToProtocols(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 251
8  libswiftCore.dylib       0x00007fff6ca8063e _dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 398
9  libswiftFoundation.dylib 0x00007fff6cc4abab $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 315
10 libswiftFoundation.dylib 0x00007fff6cc4a628 $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlF + 456
11 libswiftFoundation.dylib 0x00007fff6cd3cede $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlFTj + 14
12 libDanger.dylib          0x0000000118aee867 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyF + 1303
13 libDanger.dylib          0x0000000118aef429 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyFTo + 9
14 libsystem_c.dylib        0x00007fff6d213143 __cxa_finalize_ranges + 326
15 libsystem_c.dylib        0x00007fff6d213412 exit + 55
16 libdyld.dylib            0x00007fff6d169cd0 start + 8
17 libdyld.dylib            0x000000000000001b start + 18446603338685965139
danger-results://var/folders/fn/gwhkhbj526b_qlrl0sm8jhnxtnzk2_/T/danger-response.json

Message stacktrace:

0  swift                    0x000000011215fa85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000011215ea85 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000011216003f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6d3625fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338683898400
5  libswiftCore.dylib       0x00007fff6c911c0c $ss21__SharedStringStorageC13getCharacters_5rangeySpys6UInt16VG_So13_SwiftNSRangeatF + 172
6  libswiftCore.dylib       0x00007fff6c911d28 $ss21__SharedStringStorageC13getCharacters_5rangeySpys6UInt16VG_So13_SwiftNSRangeatFTo + 24
7  CoreFoundation           0x00007fff330a4a71 __CFStringEncodeByteStream + 1857
8  Foundation               0x00007fff35742268 -[NSString(NSStringOtherEncodings) lengthOfBytesUsingEncoding:] + 103
9  Foundation               0x00007fff3579f1aa -[NSPlaceholderString initWithString:] + 159
10 libswiftFoundation.dylib 0x00007fff6cc54886 $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLV6encode_6forKeyySS_xtKF + 3430
11 libswiftFoundation.dylib 0x00007fff6cc5cf0e $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLVyxGs05KeyedcD8ProtocolAAsAFP6encode_6forKeyySS_0P0QztKFTW + 14
12 libswiftCore.dylib       0x00007fff6c981234 $ss26_KeyedEncodingContainerBoxC6encode_6forKeyySS_0G0QztKF + 36
13 libswiftCore.dylib       0x00007fff6c97afa5 $ss22KeyedEncodingContainerV6encode_6forKeyySS_xtKF + 69
14 libDanger.dylib          0x000000011765d01c $s6Danger9ViolationV6encode2toys7Encoder_p_tKF + 300
15 libDanger.dylib          0x000000011765d2a2 $s6Danger9ViolationVSEAASE6encode2toys7Encoder_p_tKFTW + 66
16 libswiftCore.dylib       0x00007fff6ca67367 $sSE6encode2toys7Encoder_p_tKFTj + 7
17 libswiftFoundation.dylib 0x00007fff6cc4bac2 $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 4178
18 libswiftFoundation.dylib 0x00007fff6cc5ecef $s10Foundation29_JSONUnkeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLV6encodeyyxKSERzlF + 703
19 libswiftFoundation.dylib 0x00007fff6cc60049 $s10Foundation29_JSONUnkeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLVs07UnkeyedcD0AAsAEP6encodeyyqd__KSERd__lFTW + 9
20 libswiftCore.dylib       0x00007fff6c98a914 $sSasSERzlE6encode2toys7Encoder_p_tKF + 660
21 libswiftCore.dylib       0x00007fff6c98aa68 $sSayxGSEsSERzlSE6encode2toys7Encoder_p_tKFTW + 24
22 libswiftCore.dylib       0x00007fff6ca67367 $sSE6encode2toys7Encoder_p_tKFTj + 7
23 libswiftFoundation.dylib 0x00007fff6cc4bac2 $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 4178
24 libswiftFoundation.dylib 0x00007fff6cc5890f $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLV6encode_6forKeyyqd___xtKSERd__lF + 3791
25 libswiftFoundation.dylib 0x00007fff6cc5d095 $s10Foundation27_JSONKeyedEncodingContainer33_12768CA107A31EF2DCE034FD75B541C9LLVyxGs05KeyedcD8ProtocolAAsAFP6encode_6forKeyyqd___0P0QztKSERd__lFTW + 21
26 libswiftCore.dylib       0x00007fff6c9814a7 $ss26_KeyedEncodingContainerBoxC6encode_6forKeyyqd___0G0QztKSERd__lF + 39
27 libswiftCore.dylib       0x00007fff6c93f3ac $ss22KeyedEncodingContainerV6encode_6forKeyyqd___xtKSERd__lF + 76
28 libDanger.dylib          0x000000011765eee0 $s6Danger0A7ResultsV6encode2toys7Encoder_p_tKF + 704
29 libDanger.dylib          0x000000011765f523 $s6Danger0A7ResultsVSEAASE6encode2toys7Encoder_p_tKFTW + 83
30 libswiftCore.dylib       0x00007fff6ca67367 $sSE6encode2toys7Encoder_p_tKFTj + 7
31 libswiftFoundation.dylib 0x00007fff6cc4bac2 $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 4178
32 libswiftFoundation.dylib 0x00007fff6cc4a628 $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlF + 456
33 libswiftFoundation.dylib 0x00007fff6cd3cede $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlFTj + 14
34 libDanger.dylib          0x0000000117601867 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyF + 1303
35 libDanger.dylib          0x0000000117602429 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyFTo + 9
36 libsystem_c.dylib        0x00007fff6d213143 __cxa_finalize_ranges + 326
37 libsystem_c.dylib        0x00007fff6d213412 exit + 55
38 libdyld.dylib            0x00007fff6d169cd0 start + 8
39 libdyld.dylib            0x000000000000001b start + 18446603338685965139

@orta
Copy link
Member

orta commented Aug 29, 2020

from the stack: looks like its around json parsing.

8  Foundation               0x00007fff35742268 -[NSString(NSStringOtherEncodings) lengthOfBytesUsingEncoding:] + 103
9  Foundation               0x00007fff3579f1aa -[NSPlaceholderString initWithString:] + 159

maybe a null or number is being coerced into a string?

@ecerney
Copy link
Author

ecerney commented Sep 1, 2020

I'm struggling to figure out exactly why it's failing. Best I've come up with so far is that the crash is happening in Danger.swift dumpResultsAtExit(:path:)... dumpInfo.danger.results is corrupted somehow so accessing it causes the crash. I've logged the methods which add messages to the results and they everything is fine there. The results object adds each message and can print perfectly. It's just that somehow by the time dumpResultsAtExit(:path:) is called the struct is corrupted. Just printing the struct in that method will result in a seg fault.

@orta @f-meloni any idea why this may be happening?

@zenangst
Copy link

zenangst commented Sep 1, 2020

I saw simliar issues today when trying danger-swift with Xcode 12 and using Codable or other things related to JSON parsing.

@f-meloni
Copy link
Member

f-meloni commented Sep 1, 2020

So I'm convinced this might be an issue on Swift itself, the behaviour is not so different to what we had on #214 some totally random code makes it crash, in that case where some static function.

I will make some tries on a branch to see if something like using swift 5.3 toolchain or not using at exit can make it work

@ecerney
Copy link
Author

ecerney commented Sep 1, 2020

@f-meloni thanks for looking into it. I've been trying on the 5.3 toolchain and also specifying the macos version since at some point I saw a crash due to the executable trying to use macos 11 toolchain even though I'm still on 10.15.x by adding the following to Package.swift:

platforms: [
    .macOS(.v10_15),
],

At this point I can sum up the issue as:

  • All messages, warnings, etc get added to the results correctly. Printing or JSON encoding the results works fine at this point
  • By the time the dump call occurs from atexit, the results struct is corrupted in a way that makes accessing it in any way cause a segfault.

Maybe there's a step in between that I'm not sure about that you can find where this "corruption" is happening 🤷 . But yes, I agree that it is a Swift bug of some sort, not directly a Danger issue.

@f-meloni
Copy link
Member

f-meloni commented Sep 1, 2020

@ecerney I've pushed a branch called xcode_12_workaround, can you please try with that one? (please ignore the warnings, didn't fix them yet because is just a test)

@ecerney
Copy link
Author

ecerney commented Sep 1, 2020

@f-meloni That fixes it! I ran danger on both this project, and on an internal PR / Dangerfile and it worked. I haven't gone through and looked at all your changes on the branch yet to see why it fixes it, but it does!

Note: I don't have Swift 5.1.1 on this machine, so I changed the .swift-version to 5.3 and it worked fine 👍

@f-meloni
Copy link
Member

f-meloni commented Sep 1, 2020

Great! It looses some performances, because generates the JSON every time you write a warning/failure/message, but is something really minor, then is a valid workarounds in case they don't fix it with the next beta/GM

@ecerney
Copy link
Author

ecerney commented Sep 1, 2020

Ah I see, you are just dumping the results every time they are updated instead of waiting for the process to exit... Nice work around. Obviously it sucks to have to write to disk after every Violation, but 🤷

@ecerney
Copy link
Author

ecerney commented Sep 1, 2020

So I was able to run everything fine when building from your branch locally... but for some reason it fails when pulling in the branch from my repo's package.swift:

// swift-tools-version:5.3.0

import PackageDescription

let package = Package(
    name: "DangerRunner",
    products: [
        .library(
            name: "DangerDependenciesMyProduct",
            type: .dynamic,
            targets: ["DangerDependencies"]
        ) // dev
    ],
    dependencies: [
        .package(
            name: "danger-swift",
            url: "https://github.com/danger/swift.git",
            .branch("xcode_12_workaround")//, from: "3.0.0")
        ) // dev
    ],
    targets: [
        .target(name: "DangerDependencies", dependencies: ["danger-swift"]) // dev
    ]
)
0  swift                    0x00000001052c0a85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001052bfa85 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001052c103f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6d3625fd _sigtramp + 29
4  libsystem_platform.dylib 0x000000010750aa00 _sigtramp + 18446603343101592608
5  libswiftCore.dylib       0x00007fff6caae946 swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 86
6  libswiftCore.dylib       0x00007fff6ca7d5ea swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**) + 42
7  libswiftCore.dylib       0x00007fff6ca812cb _conformsToProtocols(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 251
8  libswiftCore.dylib       0x00007fff6ca8063e _dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 398
9  libswiftFoundation.dylib 0x00007fff6cc4abab $s10Foundation13__JSONEncoder33_12768CA107A31EF2DCE034FD75B541C9LLC4box_ySo8NSObjectCSgSE_pKF + 315
10 libswiftFoundation.dylib 0x00007fff6cc4a628 $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlF + 456
11 libswiftFoundation.dylib 0x00007fff6cd3cede $s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlFTj + 14
12 libDanger.dylib          0x000000010a6b69f8 $s6Danger17dumpResultsAtExit33_DA57A8538BDE0544FE0FD943A1DB0C2BLL_4pathyAA0A6RunnerC_SStF0B0L_yyF + 552
13 libsystem_c.dylib        0x00007fff6d213143 __cxa_finalize_ranges + 326
14 libsystem_c.dylib        0x00007fff6d213412 exit + 55
15 libdyld.dylib            0x00007fff6d169cd0 start + 8
16 libdyld.dylib            0x000000000000001b start + 18446603338685965139
danger-results://var/folders/fn/gwhkhbj526b_qlrl0sm8jhnxtnzk2_/T/danger-response.json

😓

@f-meloni
Copy link
Member

f-meloni commented Sep 1, 2020

DumpAtExit doesn't exist anymore in my branch, so it looks like is still using the last released version 🤔

@ecerney
Copy link
Author

ecerney commented Sep 1, 2020

Oh shoot you're right I didn't see that. Strange. The build folder has your latest code in the checkout though... will try to figure out why it may be using some other executable or something

@ecerney
Copy link
Author

ecerney commented Sep 1, 2020

@f-meloni I just created my own fork of your branch, edited one of the debug printouts and pointed my Package.swift to my fork/branch and I see my updated output, but still see the DumpAtExit crash... so not sure how that could be true. I think I need to walk away for a bit haha :D

@f-meloni
Copy link
Member

f-meloni commented Sep 2, 2020

Is possible that you are caching the .build folder and something odd is happening there?
Did you try to remove it manually before running danger-swift?

@ecerney
Copy link
Author

ecerney commented Sep 2, 2020

Ya I deleted all caches and it still failed. I think there is something weird going on with SPM. Here's what I was seeing:

  • If I run danger on my projects dangerfile FROM my projects root, it fails.
  • If I cd to the danger-swift project directory, and run the exact same command as above, but changing the paths, it works

I noticed that even though I wasn't calling anything with SPM, SPM was still building the danger-swift project which somehow makes everything work. Seems like something is going on that I'm not familiar with.

Example From my project directory (fails):

.build/debug/danger-swift pr https://github.com/myproject/iOS/pull/3179 --dangerfile scripts/swift/Danger/DangerfilePostChecks.swift --verbose

From danger-swift directory (works):

../myproject/.build/debug/danger-swift pr https://github.com/myproject/iOS/pull/3179 --dangerfile ../myproject/scripts/swift/Danger/DangerfilePostChecks.swift --verbose

@rogerluan
Copy link

Any update on this issue, guys? 🙏

@ecerney
Copy link
Author

ecerney commented Sep 14, 2020

No update from me other than I had to take a break trying to find a work around and just disabled danger for our Xcode 12 builds :/. If I get more time this week I'll continue to look into it but it seems like just a Swift bug

@f-meloni
Copy link
Member

I've opened #372
If it goes well I will release a new version, the new code should work also on older xcode and the performance change is minimum, then should be easier to test it.

@f-meloni
Copy link
Member

f-meloni commented Sep 15, 2020

I've released danger-swift 3.5.0, please give it a try and tell me if it works.

@ecerney
Copy link
Author

ecerney commented Sep 15, 2020

Edit: See below comment. Looks like an old homebrew version of danger-swift was being used instead of one created with SPM

@ecerney
Copy link
Author

ecerney commented Sep 15, 2020

Ok @f-meloni I figured out that I had a libDanger installed from homebrew... so I deleted that, and now get the error:

ERROR: Could not find a libDanger to link against at any of: [".build/debug", ".build/x86_64-unknown-linux/debug", ".build/release", "/usr/local/lib/danger"]
Or via Homebrew, or Marathon

So it looks like SPM isn't building a libDanger anymore from the danger-swift package... any idea why?

Edit:
I ran brew brew install danger/tap/danger-swift and now it works... I guess I missunderstood what the SPM was supposed to do. I thought that would build the danger-swift libs, but looks like you still need to install from homebrew as well? Either way I think everything works now. Will run it on CI to make sure.

@f-meloni
Copy link
Member

Try to uninstall it from brew, go on the folder where the Package.swift is, run swift run danger-swift ci --cwd $yourRootFolderPath and it should work.
It shouldn't need to be installed via brew to work

@ecerney
Copy link
Author

ecerney commented Sep 16, 2020

Thanks for all the help @f-meloni... Got our CI up and running with the latest danger-swift and looks like everything's good. Still need to mess with the run command / danger structure because I am still relying on the homebrew version (--cwd isn't working quite right but only spent a few minutes trying), but at least for now everything works great on Xcode 12.

@f-meloni
Copy link
Member

I think this is solved now, closing, if you have any issue feel free to re open it

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

5 participants