←back to thread

612 points dayanruben | 4 comments | | HN request time: 0s | source
Show context
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 #
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 #
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 #
kergonath ◴[] No.42902221[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 #
1. alain_gilbert ◴[] No.42902604[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 #
2. robotresearcher ◴[] No.42903404[source]
Ouch, and yuk. I stand corrected!
3. brailsafe ◴[] No.42903454[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 #
4. alain_gilbert ◴[] No.42903568[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