←back to thread

612 points dayanruben | 3 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 #
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 #
1. 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 #
2. jitl ◴[] No.42904077[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.
3. saagarjha ◴[] No.42906971[source]
You can load the coredump into GDB.