4 ms·
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
by alain_gilbert 2y ago
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 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 https://pastebin.com/8M9Dbrgj this doesn't provide anything useful either.
- Pesthuf 2y agoWhat 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): ?
- Cyph0n 2y agoWhat if the error was more descriptive out of the box? Unless of course the goal is to just compete with C++ error reporting.
- catgary 2y agoThe 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.
- deleted 2y ago[deleted]
- alain_gilbert 2y agoIf I follow the advice https://pastebin.com/8M9Dbrgj https://pastebin.com/8M9Dbrgj Not sure how that's any better... I still have no idea that the error occurred on line 2
- mojuba 2y agoYou 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.
- robotresearcher 2y agoIndeed 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.
- kergonath 2y ago> 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
- alain_gilbert 2y agoHere is the output with the environment variable set. https://pastebin.com/8M9Dbrgj https://pastebin.com/8M9Dbrgj This doesn't provide anything useful either.
- robotresearcher 2y agoOuch, and yuk. I stand corrected!
- brailsafe 2y agoSeems 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
- 2y ago
- compootr 2y agoVerbosity. That's..... yap-ple!
- AdrianEGraphene 2y agoThanks for reminding me of why I shy away from Swift and dove into the arms of Kotlin Multiplatform.
- jitl 2y agoSwift 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 https://monosnap.com/file/qhlwD6aXUW5bcl3TV5lPmKFDgjWDtD
- alain_gilbert 2y agoI'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
- jitl 2y agoI 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.
- saagarjha 2y agoYou can load the coredump into GDB.
- saagarjha 2y agoThe Swift REPL sucks for this. I would suggest you compile to a binary and use your normal debugging tools.
- g0ld3nrati0 2y agoI 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│ ```
- deleted 2y ago[deleted]