Most active commenters
  • alain_gilbert(5)
  • (3)

←back to thread

612 points dayanruben | 25 comments | | HN request time: 0.667s | source | bottom
1. alain_gilbert ◴[] No.42901749[source]
Swift is a really cool language.

But one thing that blows my mind is that if you ever encounter an "index out of range" error, the (massive) error message that you get doesn't tell you anything about where this error occurred... no line number... no nothing...

    let a = [1]
    print(a[1])
Is all you have to do to reproduce the error.

The error looks something like that https://pastebin.com/MQV82SaR

And gives you no useful information as to how it happened or how to fix it.

compare that with Golang which tells you, it happened in main.go at line 4.

    panic: runtime error: index out of range [1] with length 1
    
    goroutine 1 [running]:
    main.main()
     /Users/username/main.go:4 +0x15
    exit status 2
EDIT: with the LLVM_SYMBOLIZER_PATH set https://pastebin.com/8M9Dbrgj this doesn't provide anything useful either.
replies(8): >>42901838 #>>42901880 #>>42901928 #>>42903264 #>>42903913 #>>42906968 #>>42907652 #>>42944126 #
2. mojuba ◴[] No.42901838[source]
You have a stack dump, which means you will get all the information if you symbolicate your crash report. Xcode can do it for you automatically, but some manual methods also exist.
replies(1): >>42901964 #
3. Pesthuf ◴[] No.42901880[source]
What if you follow the advice here

>Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):

?

replies(3): >>42902028 #>>42902455 #>>42902472 #
4. compootr ◴[] No.42901928[source]
Verbosity. That's..... yap-ple!
5. robotresearcher ◴[] No.42901964[source]
Indeed the error report being complained about explains this and tells you how to fix it.

Maybe the friendly default would be to have the symbolicated reports on, but perhaps this has performance impact so it’s off.

replies(2): >>42902221 #>>42902925 #
6. Cyph0n ◴[] No.42902028[source]
What if the error was more descriptive out of the box? Unless of course the goal is to just compete with C++ error reporting.
replies(1): >>42902349 #
7. kergonath ◴[] No.42902221{3}[source]
> Maybe the friendly default would be to have the symbolicated reports on

As a comment just below says, the solution is quite simple:

> ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it

replies(1): >>42902604 #
8. catgary ◴[] No.42902349{3}[source]
The goal is to probably avoid duplicating efforts when llvm-symbolize already exists.

There’s obviously a snarky comment to make here about Go developers and duplicating efforts.

9. ◴[] No.42902455[source]
10. alain_gilbert ◴[] No.42902472[source]
If I follow the advice

https://pastebin.com/8M9Dbrgj

Not sure how that's any better... I still have no idea that the error occurred on line 2

11. alain_gilbert ◴[] No.42902604{4}[source]
Here is the output with the environment variable set.

https://pastebin.com/8M9Dbrgj

This doesn't provide anything useful either.

replies(2): >>42903404 #>>42903454 #
12. ◴[] No.42902925{3}[source]
13. AdrianEGraphene ◴[] No.42903264[source]
Thanks for reminding me of why I shy away from Swift and dove into the arms of Kotlin Multiplatform.
replies(1): >>42904741 #
14. robotresearcher ◴[] No.42903404{5}[source]
Ouch, and yuk. I stand corrected!
15. brailsafe ◴[] No.42903454{5}[source]
Seems like there's an architecture error or something, the last line indicates you might have an error with the flag:

> zsh: illegal hardware instruction LLVM_SYMBOLIZER_PATH=/usr/local/opt/llvm/bin/llvm-symbolizer swift main.swift

replies(1): >>42903568 #
16. alain_gilbert ◴[] No.42903568{6}[source]
that's not related to the symbolizer thing. It seems to just be part of the "index out of range" crash. I get the same thing without using the symbolizer.

    zsh: illegal hardware instruction  swift main.swift
17. jitl ◴[] No.42903913[source]
Swift outside of Xcode is a bit rough around the edges, I think because more attention goes into making Xcode friendly. I opened Xcode, made a new playground, and hit run, the code crashes and highlights the line where the error occurred in red. Not to excuse Swift's jankyness, just saying that the kind of default experience is more an IDE-first design compared to Go's very good unix-first design.

https://monosnap.com/file/qhlwD6aXUW5bcl3TV5lPmKFDgjWDtD

replies(1): >>42903977 #
18. alain_gilbert ◴[] No.42903977[source]
I'm just curious, if I was to run my application on a linux server.

How would I ever know what caused the crash?

when I compile using `swiftc main.swift` and run with `./main`, the error seems even more useless.

all I get is:

    Swift/ContiguousArrayBuffer.swift:600: Fatal error: Index out of range
    zsh: illegal hardware instruction  ./main
replies(2): >>42904077 #>>42906971 #
19. jitl ◴[] No.42904077{3}[source]
I don't know, I write Swift on a Mac targeting macOS or iOS. I usually have Xcode open to build/run/debug and for documentation lookup, and alternate between that and VSCode for actually writing the code; worst thing about Xcode for me is the find-replace, that's probably the biggest reason I keep VSCode open.
20. WD-42 ◴[] No.42904741[source]
Yea because kotlin without a jetbrains ide is such a good experience.
replies(1): >>42905108 #
21. abenga ◴[] No.42905108{3}[source]
At least the jetbrains ide exists for all major platforms.
22. saagarjha ◴[] No.42906968[source]
The Swift REPL sucks for this. I would suggest you compile to a binary and use your normal debugging tools.
23. saagarjha ◴[] No.42906971{3}[source]
You can load the coredump into GDB.
24. g0ld3nrati0 ◴[] No.42907652[source]
I am getting proper error feedback,

``` swift_hello_main + 322 in swift-hello at /home/fermi/Documents/temp/swift-hello/Sources/main.swift:64:8

    62│
    63│ let a = [1]
    64│ print(a[1])
      │        ▲
    65│
```
25. ◴[] No.42944126[source]