Visual Studio CodeによるRubyのデバッグ
Mac環境でこちらの記事などを参考にVSCodeでRubyのデバッグをしようとすると以下のエラーが発生しました。
CSV::MalformedCSVError: Invalid byte sequence in US-ASCII in line 1.
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/2.6.0/csv/parser.rb:313:in `rescue in parse'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/2.6.0/csv/parser.rb:296:in `parse'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/2.6.0/csv.rb:1236:in `each'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/2.6.0/csv.rb:1236:in `each'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/2.6.0/csv.rb:510:in `block in foreach'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/2.6.0/csv.rb:657:in `open'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/2.6.0/csv.rb:509:in `foreach'
/Users/hoge/Development/test/main.rb:7:in `<top (required)>'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ruby-debug-ide-0.7.0/lib/ruby-debug-ide.rb:100:in `debug_load'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ruby-debug-ide-0.7.0/lib/ruby-debug-ide.rb:100:in `debug_program'
/Users/hoge/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ruby-debug-ide-0.7.0/bin/rdebug-ide:187:in `<top (required)>'
/Users/hoge/.rbenv/versions/2.6.5/bin/rdebug-ide:23:in `load'
/Users/hoge/.rbenv/versions/2.6.5/bin/rdebug-ide:23:in `<top (required)>'
ruby main.rb
などでコンソール上での実行では問題なく動くのですが、CSVの読み込みの際にエンコーディングのエラーが発生しました。
こちらで解決しました。
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/main.rb",
"useBundler": true,
"env": {
"LANG": "en_US.UTF-8",
"LC_COLLATE": "en_US.UTF-8",
"LC_CTYPE": "en_US.UTF-8",
"LC_MESSAGES": "en_US.UTF-8",
"LC_MONETARY": "en_US.UTF-8",
"LC_NUMERIC": "en_US.UTF-8",
"LC_TIME": "en_US.UTF-8",
"LC_ALL": "en_US.UTF-8"
}
}
]
}