rails debug - debugging console terminates the app execution - ruby-on-rails

I am using gem 'debug', '~>1.5.0', '<= 1.6.0' in my rails6 app and upon writing continue command on the debugging console, the console doesn't continue the app running state but terminates it with some errors I do not understand.
Following is the error log upon in the command line :
[16, 25] in ~/Desktop/app-name/app/controllers/admin/units_controller.rb
16| # return redirect_to import_admin_tenant_site_units_path
17|
18| # file = File.open(file)
19| # csv = CSV.parse(file, headers: true)
20|
=> 21| binding.b
22|
24| # CSV.foreach(file, headers: true) do |row|
25| # logger.debug("++++++++Inside.+++++++++")
=>#0 Admin::UnitsController#import at ~/Desktop/app-name/app/controllers/admin/units_controller.rb:21
#1 ActionController::BasicImplicitRender#send_action(method="import", args=[]) at ~/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.6/lib/action_controller/metal/basic_implicit_render.rb:6
# and 76 frames (use `bt' command for all frames)
(rdbg) continue # command
Redirected to http://localhost:3000/admin/tenants/1/sites/1/units/import
Completed 200 OK in 216610ms (ActiveRecord: 2.0ms | Allocations: 139037)
#<Thread:0x000055f9a2607c18#/home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:130 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
6: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:134:in `block in daemon_mode'
5: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:186:in `mqtt_loop'
4: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:190:in `loop_misc'
3: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/connection_helper.rb:151:in `check_keep_alive'
2: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:48:in `send_pingreq'
1: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:36:in `send_packet'
/home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:36:in `write': Connection reset by peer (Errno::ECONNRESET)
6: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:134:in `block in daemon_mode'
5: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:186:in `mqtt_loop'
4: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:190:in `loop_misc'
3: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/connection_helper.rb:151:in `check_keep_alive'
2: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:48:in `send_pingreq'
1: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:34:in `send_packet'
/home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:41:in `rescue in send_packet': PahoMqtt::WritingException
Exiting
Traceback (most recent call last):
6: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:134:in `block in daemon_mode'
5: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:186:in `mqtt_loop'
4: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:190:in `loop_misc'
3: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/connection_helper.rb:151:in `check_keep_alive'
2: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:48:in `send_pingreq'
1: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:36:in `send_packet'
/home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:36:in `write': Connection reset by peer (Errno::ECONNRESET)
6: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:134:in `block in daemon_mode'
5: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:186:in `mqtt_loop'
4: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/client.rb:190:in `loop_misc'
3: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/connection_helper.rb:151:in `check_keep_alive'
2: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:48:in `send_pingreq'
1: from /home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:34:in `send_packet'
/home/meet/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/paho-mqtt-1.0.12/lib/paho_mqtt/sender.rb:41:in `rescue in send_packet': PahoMqtt::WritingException
I am new to using debugging console and debugging packages to debug apps and I am following this one youtube tutorial were the tutor has used this gem and I expect that my app continues execution on the continue command and not terminate it.
Youtube video link - https://youtu.be/EJ8FZMLsVVQ hehe.
My system is Ubuntu 20.04 LTS

Related

Savon ruby gem getting Savon::SOAPFault on request

My code is pretty simple:
client = Savon.client(wsdl: wsdl_url, follow_redirects: true)
response = client.call(:obtener_cotizacion, message: { fecha: '2022-08-02' })
I get this error:
Traceback (most recent call last):
8: from bin/console:8:in `<main>'
7: from (irb):82
6: from /app/vendor/bundle/ruby/2.7.0/gems/savon-2.13.0/lib/savon/client.rb:37:in `call'
5: from /app/vendor/bundle/ruby/2.7.0/gems/savon-2.13.0/lib/savon/operation.rb:65:in `call'
4: from /app/vendor/bundle/ruby/2.7.0/gems/savon-2.13.0/lib/savon/operation.rb:76:in `create_response'
3: from /app/vendor/bundle/ruby/2.7.0/gems/savon-2.13.0/lib/savon/operation.rb:76:in `new'
2: from /app/vendor/bundle/ruby/2.7.0/gems/savon-2.13.0/lib/savon/response.rb:20:in `initialize'
1: from /app/vendor/bundle/ruby/2.7.0/gems/savon-2.13.0/lib/savon/response.rb:132:in `raise_soap_and_http_errors!'
Savon::SOAPFault ((S:Client) Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxParsingException: Trying to declare prefix 'xmlns' (illegal as per NS 1.1 #4))
at [row,col {unknown-source}]: [1,585]
I have no idea what that means, I have never declared any prefix in my other integrations.
Any help would be appreciated, thanks!
The error seams to be introduced in this commit: https://github.com/savonrb/savon/commit/045082c9d18ed538da072b4a4681e79c16dac17b
Have you tried downgrading Savonrb to version 2.12.1?

Getting Error - PG::UndefinedColumn (ERROR: column d.adsrc does not exist on heroku with postgres version 13.3

I am getting below error while running my Rails application on Heroku
WARN -- : [6a47e5ee-5dd5-452b-80c1-3b7c4fd6b528] Failed to submit event: PG::UndefinedColumn: ERROR: column d.adsrc does not exist
2021-07-08T07:59:39.814486+00:00 app[web.1]: LINE 1: ...format_type(a.atttypid, a.atttypmod) AS sql_type, d.adsrc AS...
2021-07-08T07:59:39.814487+00:00 app[web.1]: ^
2021-07-08T07:59:39.814488+00:00 app[web.1]:
2021-07-08T07:59:39.815559+00:00 app[web.1]: F, [2021-07-08T07:59:39.815471 #4] FATAL -- : [6a47e5ee-5dd5-452b-80c1-3b7c4fd6b528]
2021-07-08T07:59:39.815561+00:00 app[web.1]: [6a47e5ee-5dd5-452b-80c1-3b7c4fd6b528] PG::UndefinedColumn (ERROR: column d.adsrc does not exist
2021-07-08T07:59:39.815561+00:00 app[web.1]: LINE 1: ...format_type(a.atttypid, a.atttypmod) AS sql_type, d.adsrc AS...
2021-07-08T07:59:39.815562+00:00 app[web.1]: ^
As per search, I get that this is happening with Postgres 12 but I am getting the same issue on Postgres 13.3 on Heroku
With the same Postgres version on local, it works fine, so might be something with Heroku but I am not getting what it is, help, please !!
adsrc was removed in Postgres version 12 see here 12 Release notes. I'm guessing that in your local situation you are connecting to database version 11 or less.

Is there any way to set a break point for debug in the environment in which gems like binding.pry are not installed?

From this April, I participated in a new project in which gems for debug are not installed and I am not allowed to install new ones.
I would like to set a break point and see the inside of variables like binding.pry.
I googled to debug in such a way without newly installing gems or by using extensions of VScode, but most of the pages require me to install ones.
It would be highly appreciated if you would share with me your ideas to debug in the way.
== Additional Information on April 8th, 2020 ==
Ruby version is 1.8.7.
Rails version is 2.3.5.
Unfortunately, Ruby doesn't really have a built-in breakpoint-based debugger in that sense.
The closest thing you can do is start an IRB session mid-program, which halts it and allows you to inspect the current state of the program by evaluating Ruby commands. This is available in Ruby 2.4 and above as binding.irb. (There are docs available for this on the Binding class.)
IRB doesn't let you step forwards like Pry with Pry-Nav does, but you can just insert binding.irb expressions in as many places as you need, and exit from IRB to "step" to the next one.
Take ths simple program. I want to check the value of those three variables I've assigned, so I put binding.irb there:
puts "=== Hello! ==="
a = 1
b = 2
c = 3
binding.irb
puts "=== Goodbye! ==="
Upon running this program, Ruby will give you an IRB prompt after it's evaluated c = 3, where you can run Ruby code to check values and whatnot (type exit to leave):
=== Hello! ===
From: test.rb # line 7 :
2:
3: a = 1
4: b = 2
5: c = 3
6:
=> 7: binding.irb
8:
9: puts "=== Goodbye! ==="
irb(main):001:0> a
=> 1
irb(main):002:0> b
=> 2
irb(main):003:0> c
=> 3
irb(main):004:0> exit
=== Goodbye! ===

Amazon Beanstalk ebcli.objects.exceptions.ServiceError: Failed to deploy application

Creating application version archive "app-8dfd-161111_001943".
Uploading: [##################################################] 100% Done...
INFO: Environment update is starting.
INFO: Deploying new version to instance(s).
ERROR: [Instance: i-97f2b48f] Command failed on instance. Return code: 1 Output: (TRUNCATED)...b:1:in `<top (required)>'
/var/app/ondeck/config/environment.rb:5:in `<top (required)>'
/opt/rubies/ruby-2.3.1/bin/bundle:23:in `load'
/opt/rubies/ruby-2.3.1/bin/bundle:23:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace).
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Unsuccessful command execution on instance id(s) 'i-97f2b48f'. Aborting the operation.
ERROR: Failed to deploy application.
Traceback (most recent call last):
File "/usr/local/bin/eb", line 11, in
load_entry_point('awsebcli==3.8.3', 'console_scripts', 'eb')()
File "/usr/local/lib/python2.7/dist-packages/ebcli/core/ebcore.py", line 150, in main
app.run()
File "/usr/local/lib/python2.7/dist-packages/cement/core/foundation.py", line 797, in run
return_val = self.controller._dispatch()
File "/usr/local/lib/python2.7/dist-packages/cement/core/controller.py", line 472, in _dispatch
return func()
File "/usr/local/lib/python2.7/dist-packages/cement/core/controller.py", line 478, in _dispatch
return func()
File "/usr/local/lib/python2.7/dist-packages/ebcli/core/abstractcontroller.py", line 57, in default
self.do_command()
File "/usr/local/lib/python2.7/dist-packages/ebcli/controllers/deploy.py", line 94, in do_command
staged=self.staged, timeout=self.timeout, source=self.source)
File "/usr/local/lib/python2.7/dist-packages/ebcli/operations/deployops.py", line 45, in deploy
can_abort=True)
File "/usr/local/lib/python2.7/dist-packages/ebcli/operations/commonops.py", line 91, in wait_for_success_events
if _is_success_string(event.message):
File "/usr/local/lib/python2.7/dist-packages/ebcli/operations/commonops.py", line 264, in _is_success_string
raise ServiceError(message)
ebcli.objects.exceptions.ServiceError: Failed to deploy application.
This error appears when I deploy my application to eb (eb deploy). How do I deploy this successfully?
It looks like your application failed to deploy onto the EC2 instance. You should be able to get a detailed log of what went wrong by downloading the logs and checking them.
You can get the logs with the EB CLI like so:
eb logs --all
The log file that will have the deployment logs will be the /var/log/eb-activity.log which you can find here after running the above command:
/PROJECT-ROOT/.elasticbeanstalk/logs/latest/i-xxxxxxx/var/log/eb-activity.log
The error logs of why your instance failed to delete should be in this log file.

Errno::ETIMEDOUT: Connection timed out - connect(2)

In production, I'm occasionally getting the following error:
Errno::ETIMEDOUT: Connection timed out - connect(2)
It only seems to be happening when I generate a PDF using the prawn gem that contains an image that was uploaded by paperclip/aws-sdk to s3. This probably only happens a couple times a week on an action that is used hundreds of times a day (with no issues), but it results in a 500 error when it does fail.
The trace is:
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`initialize'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`connect'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:53:in
`timeout'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:101:in
`timeout'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`connect'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:553:in
`do_start'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:542:in
`start'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:242:in
`open_http'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:616:in
`buffer_open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:164:in
`open_loop'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:162:in
`catch'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:162:in
`open_loop'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:132:in
`open_uri'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:518:in
`open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:30:in
`open'
....rb:57:in `render_image_to_pdf'
Line 57:
pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
Setup:
Rails 3.0.10
Ruby 1.8.7EE
Prawn 0.11.1
AWS-SDK 1.3.3
Paperclip 2.5.2
What can I do to prevent this error?
One option is to catch the exception and try again:
begin
pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
rescue Errno::ETIMEDOUT
# try one more time, or use retry with a counter to attempt a limited number of times
pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
end
You may also want to put some diagnostics (either logging or generating an Airbrake) that notifies you so you can see if there is some sort of pattern to the failures.
I have been getting the same error in Amazon EC2 when using aws-sdk to spawn new server instances. Here's what I know:
I have a function (sleep_while_not_running) which tests the instance.status:
def sleep_while_not_running(instance)
print "waiting on system: "
$stdout.flush
while instance.status != :running
print "."
$stdout.flush
sleep 1
end
puts "resuming."
end
After sleep_while_not_running returns, I assume that we should be able to connect (as follows):
Net::SSH.start(instance.ip_address,'root',:key_data=>[key_pair.private_key]) do |ssh|
sleep_while_not_running(instance)
puts "testing SSH connectivity."
puts ssh.exec("uname -a")
puts " "
What happens is the same time-out error you describe. Investigating manually, I have found that--
a. If I wait until "Status Checks" (in the management console) shows that the new instance has "Passed 2/2 Checks", then I can SSH in manually just fine using the same key pair used by the script.
b. sleep_while_not_running checks instance.status (which says "running" long before the server is fully baked.
c. I can find no call in aws-sdk to check the "status checks" I would check in the management console, but I suspect that is where the solution exists.
P.S. I realize this isn't an "answer" but it may help identify a solution.

Resources