Sublime Ruby Debugger—connection error with rspec - ruby

I am about to code with SublimeText and I have installed the Ruby Debugger Plugin. Everything works fine, but if I want to debug some rspec's the debugger disconnects due to this error:
Debugger exception: [Errno 104] Connection reset by peer
StackTrace: Traceback (most recent call last):
File "/home/philipp/.config/sublime-text-3/Packages/Ruby Debugger/debugge/ruby_imp/ruby_debugger_connector.py", line 102, in reader_thread
bytes = self.client.recv(4096)
ConnectionResetError: [Errno 104] Connection reset by peer
the spec file I am debugging looks like this:
1 | require_relative '../spec_helper'
2 |
3 | describe Parser do
4 | before :each do
5 | #parser = Parser.new '../../../file.txt'
6 | end
7 |
8 | describe '#new' do
9 | it 'raises an error if no input file is given' do
10| lambda { Parser.new }.should raise_exception ArgumentError
11| end
12| end
13| end
I have set a breakpoint at line 5, but the debugger never overcomes line 3. What could that be?

Related

Why isn't "srb tc" finding the "expect" and "eq" methods for my RSpec tests?

I'm trying out Sorbet in an experimental open-source project (ruby_crystal_codemod). I can't figure out how to get the type-checking to work with some RSpec tests in a nested test project. When I run srb tc, I am seeing some type-checking errors like this:
spec/src/example_class_annotated_spec.rb:6: Method it does not exist on T.class_of(<root>) https://srb.help/7003
6 | it 'should add #foo and #bar' do
7 | instance = ExampleClass.new(2, 3, 4)
8 | expect(instance.add).to eq 5
9 | end
spec/src/example_class_annotated_spec.rb:8: Method expect does not exist on T.class_of(<root>) https://srb.help/7003
8 | expect(instance.add).to eq 5
^^^^^^^^^^^^^^^^^^^^
https://github.com/sorbet/sorbet/tree/67cd17f5168252fdec1ad04839b31fdda8bc6155/rbi/core/kernel.rbi#L2662: Did you mean: Kernel#exec?
2662 | def exec(*args); end
^^^^^^^^^^^^^^^
spec/src/example_class_annotated_spec.rb:8: Method eq does not exist on T.class_of(<root>) https://srb.help/7003
8 | expect(instance.add).to eq 5
^^^^
# etc.
Here is the source directory for the nested project on GitHub.
spec/src/example_class_annotated_spec.rb
spec/spec_helper.rb
src/example_class_annotated.rb
You should be able to run the following commands to reproduce the type error:
cd /tmp
git clone https://github.com/DocSpring/ruby_crystal_codemod.git
cd ruby_crystal_codemod
git checkout sorbet-rspec-type-checking-error
cd spec/fixtures/rspec_project/
bundle install
bundle exec srb tc
You should see these type errors:
spec/src/example_class_annotated_spec.rb:6: Method it does not exist on T.class_of(<root>) https://srb.help/7003
6 | it 'should add #foo and #bar' do
7 | instance = ExampleClass.new(2, 3, 4)
8 | expect(instance.add).to eq 5
9 | end
# etc.
Is there something wrong with the RBI files at spec/fixtures/rspec_project/sorbet/rbi/gems/rspec-core.rbi, etc.?
Maybe using tapioca to generate the type definitions would help https://github.com/Shopify/tapioca

POSTing XML to a lambda in Localstack always throws 502 Bad Gateway

We have a lambda deployed to Localstack with an API gateway endpoint configured as AWS_PROXY. Invoking the Lambda with a POST works if the body is empty or contains JSON, however, sending XML in the body (regardless of the Content-Type) always returns a 502. The error in the Localstack log is:
localstack_1 | 2019-11-14T13:29:49:ERROR:localstack.services.generic_proxy: Error forwarding request: Expecting value: line 1 column 1 (char 0) Traceback (most recent call last):
localstack_1 | File "/opt/code/localstack/localstack/services/generic_proxy.py", line 240, in forward
localstack_1 | path=path, data=data, headers=forward_headers)
localstack_1 | File "/opt/code/localstack/localstack/services/apigateway/apigateway_listener.py", line 35, in forward_request
localstack_1 | data = data and json.loads(to_str(data))
localstack_1 | File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
localstack_1 | return _default_decoder.decode(s)
localstack_1 | File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
localstack_1 | obj, end = self.raw_decode(s, idx=_w(s, 0).end())
localstack_1 | File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
localstack_1 | raise JSONDecodeError("Expecting value", s, err.value) from None
localstack_1 | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I thought AWS_PROXY integration was supposed to pass data direct to the Lambda without any attempt to decode or validate? Is there a way to set up the API gateway integration so that it will happily accept XML?
This is the function that we're using to set up API Gateway after the lambda has been deployed: https://gist.github.com/jgwconsulting/0c5597a661cbc6d29aaa346b2aed5020
This looks to be a problem with Localstack always assuming that POSTed data will be JSON and attempting to parse it to a Python dictionary.
I've created an issue to track the problem here and will attempt to make a PR to fix it if I get time: https://github.com/localstack/localstack/issues/1762

How to resolve Mixlib::ShellOut::ShellCommandFailed error

I am trying to mock the data of node and run chefspec. But facing this error. Chefspec version=7.3.4
Chef version=13.9.1
Is there any problem with the simulation? how do I resolve the handler error?
Is there something I'm missing here? How can I debug the Mixlib::ShellOut::CommandTimeout?
================================================================================
Error executing action `install` on resource 'python_package[setuptools]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of ["/usr/bin/python2.7", "-", "setuptools==40.5.0"] ----
STDOUT:
STDERR: No handlers could be found for logger "pip._internal.index"
Traceback (most recent call last):
File "<stdin>", line 43, in <module>
File "/usr/local/lib/python2.7/dist-packages/pip/_internal/index.py", line 543, in find_requirement
'No matching distribution found for %s' % req
pip._internal.exceptions.DistributionNotFound: No matching distribution found for setuptools==40.5.0
---- End output of ["/usr/bin/python2.7", "-", "setuptools==40.5.0"] ----
Ran ["/usr/bin/python2.7", "-", "setuptools==40.5.0"] returned 1
Resource Declaration:
---------------------
# In /chef-recipes/cookbooks/poise-python/files/halite_gem/poise_python/python_providers/base.rb
138: python_package 'setuptools' do
139: parent_python new_resource
140: version setuptools_version if setuptools_version.is_a?(String)
141: end
142: end
Compiled Resource:
------------------
# Declared in /chef-recipes/cookbooks/poise-python/files/halite_gem/poise_python/python_providers/base.rb:138:in `install_setuptools'
python_package("setuptools") do
package_name "setuptools"
action [:install]
default_guard_interpreter :default
declared_type :python_package
cookbook_name :"poise-python"
parent_python python_runtime[2]
version "40.5.0"
timeout 900
end
System Info:
------------
chef_version=13.9.1
platform=ubuntu
platform_version=16.04
ruby=ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
program_name=/usr/local/rvm/gems/ruby-2.4.2/bin/rspec
executable=/usr/local/rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks

QIIME2 dada2 rlang.so error

I was running the QIIME2 moving picture tutorial, at the dada2 step,
I was running:
qiime dada2 denoise-single \
--i-demultiplexed-seqs demux.qza \
--p-trim-left 0 \
--p-trunc-len 120 \
--o-representative-sequences rep-seqs-dada2.qza \
--o-table table-dada2.qza
and ran into this error:
Plugin error from dada2:
An error was encountered while running DADA2 in R (return code 1),
please inspect stdout and stderr to learn more.
Debug info has been saved to /tmp/qiime2-q2cli-err-52fzrvlu.log.
I then open the file: /tmp/qiime2-q2cli-err-52fzrvlu.log. this is what I found:
Running external command line application(s). This may print messages
to stdout and/or stderr. The command(s) being run are below. These
commands cannot be manually re-run as they will depend on temporary
files that no longer exist.
Command: run_dada_single.R
/tmp/qiime2-archive-pco6y5vm/fe614b44-775f-41b1-9ee3-04319005e830/data
/tmp/tmpda8dnyve/output.tsv.biom /tmp/tmpda8dnyve 120 0 2.0 2
consensus 1.0 1 1000000
R version 3.3.1 (2016-06-21) Loading required package: Rcpp Error in
dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared
object '/home/cao/lib/R/library/rlang/libs/rlang.so':
/home/cao/lib/R/library/rlang/libs/rlang.so: undefined symbol:
R_ExternalPtrAddrFn In addition: Warning message: package ‘Rcpp’ was
built under R version 3.4.1 Error: package or namespace load failed
for ‘dada2’ Execution halted Traceback (most recent call last): File
"/home/cao/miniconda3/envs/qiime2-2017.7/lib/python3.5/site-packages/q2_dada2/_denoise.py",
line 126, in denoise_single
run_commands([cmd]) File "/home/cao/miniconda3/envs/qiime2-2017.7/lib/python3.5/site-packages/q2_dada2/_denoise.py",
line 35, in run_commands
subprocess.run(cmd, check=True) File "/home/cao/miniconda3/envs/qiime2-2017.7/lib/python3.5/subprocess.py",
line 398, in run
output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['run_dada_single.R',
'/tmp/qiime2-archive-pco6y5vm/fe614b44-775f-41b1-9ee3-04319005e830/data',
'/tmp/tmpda8dnyve/output.tsv.biom', '/tmp/tmpda8dnyve', '120', '0',
'2.0', '2', 'consensus', '1.0', '1', '1000000']' returned non-zero
exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"/home/cao/miniconda3/envs/qiime2-2017.7/lib/python3.5/site-packages/q2cli/commands.py",
line 222, in __call__
results = action(**arguments) File "<decorator-gen-252>", line 2, in denoise_single File
"/home/cao/miniconda3/envs/qiime2-2017.7/lib/python3.5/site-packages/qiime2/sdk/action.py",
line 201, in callable_wrapper
output_types, provenance) File "/home/cao/miniconda3/envs/qiime2-2017.7/lib/python3.5/site-packages/qiime2/sdk/action.py",
line 334, in _callable_executor_
output_views = callable(**view_args) File "/home/cao/miniconda3/envs/qiime2-2017.7/lib/python3.5/site-packages/q2_dada2/_denoise.py",
line 137, in denoise_single
" and stderr to learn more." % e.returncode) Exception: An error was encountered while running DADA2 in R (return code 1), please
inspect stdout and stderr to learn more.
I then 'sudo R' and installed the Rcpp and rlang packages, but still got the the same error when I run the same code as I first did:
qiime dada2 denoise-single \
--i-demultiplexed-seqs demux.qza \
--p-trim-left 0 \
--p-trunc-len 120 \
--o-representative-sequences rep-seqs-dada2.qza \
--o-table table-dada2.qza
I figured it out:
it was the R version: i uninstalled R3.4 and install R 3.3 and everythign works

Replace strings in a file with ruby

I'm trying to create a program that reads ps and outputs the pid and commandline, but if the process was started by the kernel it should return a blank line.
require 'fileutils'
procs=`ps -eo pid,cmd`
o = File.open("proc","w")
f = o.write("proc")
o.close
f_in = File.open('proc', 'r')
f_out = File.open('procs', 'w')
replace = ""
f_in.each do |line|
if line =~ (/\s*\[(\w+)\]\$/)
f_out << "\n"
else
f_out << line
end
end
f_out.write("procs")
f_in.close
f_out.close
FileUtils.mv "procs", ["proc", Time.now.strftime("%Y-%m-%d")].join(".")
ps -eo pid,cmd like:
PID CMD
1 /sbin/init
2 [migration/0]
3 [ksoftirqd/0]
4 [watchdog/0]
5 [events/0]
6 [khelper]
7 [kthread]
8 [xenwatch]
9 [xenbus]
17 [kblockd/0]
I want to remove all of the lines in brackets but keep the PID like this:
PID CMD
1 /sbin/init
2
3
4
5
6
7
8
9
17
This looks like it will do it:
File.open("proc.#{ Time.now.strftime('%F') }", 'w') do |fo|
fo.puts `ps -eo pid,cmd`.lines.map{ |li| li[ /^([^\[]+)/, 1] }
end
li[ /^([^\[]+)/, 1] means "capture everything from the start of the line that isn't a '[' and return it.
It created a file called "proc.2011-04-16" which looks like:
PID CMD
1 /sbin/init
2
3
4
5
[...]
255 upstart-udev-bridge --daemon
296 rsyslogd -c4
303 dbus-daemon --system --fork
315 udevd --daemon
398 avahi-daemon: running
443 avahi-daemon: chroot helper
493
[...]
EDIT: There were a couple things I thought could be more succinct:
File.open('proc.' + Date.today.strftime, 'w') do |fo|
fo.puts `ps -eo pid,cmd`.gsub( /\s+\[.+?\]$/, '')
end
Just do
string.gsub(/\[.*?\]/, '')
or
string.gsub(/\[[^\[\]]*\]/, '')

Resources