I'm doing a test for receiving emails with Mailman gem in Rails4.2.1 (Ruby 2.1.6).
Receiving email is good, but I can't insert the data to a table with strong parameters.
There, the exception error seems to occur by the error
"...ERROR -- : private method `require' called for
#<ActiveSupport::HashWithIndifferentAccess:..."
I'd like to insert data with strong parameters after receiving email by using mailman gem.
Mailman gem provides Matcher referred to a params, so it may affect such problem.
Do I have something wrong ?
How can I use the strong parameters in mailman receiver ?
Thank you in advance.
My codes are as follows: mailman_server.rb
require 'rubygems'
require 'bundler/setup'
require 'mailman'
Mailman.config.poll_interval = 10
Mailman.config.pop3 = {
server: 'pop.sample.com',
username: 'test#sample.com',
password: 'password',
port: 110,
ssl: false
}
Mailman::Application.run do
to "%event%#sample.com" do
begin
UserMailer.receive(message)
params[:message] = {}
params[:message][:title] = message.subject
params[:message][:description] = message.text_part.body.decoded
#message = Message.new(params.require(:message).permit(:title, :description))
if #message.save
puts 'Message was successfully created.'
end
rescue Exception => e
Mailman.logger.error "Exception occurred while receiving message:n#{message}"
Mailman.logger.error [e, *e.backtrace].join("n")
end
end
end
And user_mailer.rb:
class UserMailer < ApplicationMailer
def receive(message)
end
end
I tried another method, but got the following similar error.
E, [2015-09-15T15:29:26.944316 #2316] ERROR -- : Error encountered processing message: #<Net::POPMail 1>
NoMethodError: private method `require' called for #<ActiveSupport::HashWithIndifferentAccess:0x4523cb8>
C:/Users/gworth-sny/Z_userfolder/rails/mailman_model/app/controllers/messages_rec.rb:10:in `receive'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/router.rb:58:in `route'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/message_processor.rb:23:in `block in process'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/middleware.rb:33:in `call'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/middleware.rb:33:in `block in run'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/middleware.rb:38:in `call'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/middleware.rb:38:in `run'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/message_processor.rb:22:in `process'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/receiver/pop3.rb:49:in `block in get_messages'
C:/Ruby21/lib/ruby/2.1.0/net/pop.rb:665:in `each'
C:/Ruby21/lib/ruby/2.1.0/net/pop.rb:665:in `each_mail'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/receiver/pop3.rb:47:in `get_messages'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/application.rb:140:in `block in polling_loop'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/application.rb:137:in `loop'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/application.rb:137:in `polling_loop'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/application.rb:87:in `run'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/mailman-0.7.3/lib/mailman/application.rb:15:in `run'
script/mailman_server.rb:19:in `<main>'
The codes that I changed are as follows.
Mailman::Application.run do
to "%event%#sample.com", "MessagesRec#receive" do
begin
rescue Exception => e
Mailman.logger.error "Exception occurred while receiving message:n#{message}"
Mailman.logger.error [e, *e.backtrace].join("n")
end
end
end
messages_rec.rb
class MessagesRec < ApplicationController
def receive(message, params)
puts "------------ #{message}"
params[:message] = {}
params[:message][:title] = message.subject
params[:message][:description] = message.text_part.body.decoded
puts "------------ #{params}"
#message = Message.new(params.require(:message).permit(:title, :description))
if #message.save
puts 'Message was successfully created.'
else
puts 'Message was lost.'
end
end
end
Does this error "NoMethodError: private method `require' called " mean that can not use in this mailman process ?
How is it possible ?
Thank you in advance.
Related
I have used whenever gems,where i have schedule more than 500 mails to execute at a particular time,but its not going.But if i send 15 or 20 email then it goes.I am getting the following in my output file of whenever.
rake aborted!
Net::SMTPServerBusy: 452 4.5.3 Error: too many recipients
/home/indiba3/.rvm/gems/ruby-2.1.8/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp.rb:114:in `block in deliver!'
/home/indiba3/.rvm/gems/ruby-2.1.8/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp.rb:113:in `deliver!'
/home/indiba3/.rvm/gems/ruby-2.1.8/gems/mail-2.6.4/lib/mail/message.rb:253:in `deliver!'
/home/indiba3/.rvm/gems/ruby-2.1.8/gems/actionmailer-4.2.4/lib/action_mailer/message_delivery.rb:77:in `deliver_now!'
/home/indiba3/.rvm/gems/ruby-2.1.8/gems/actionmailer-4.2.4/lib/action_mailer/message_delivery.rb:95:in `deliver!'
/home/indiba3/hrms/lib/tasks/email_tasks.rake:25:in `block (2 levels) in <top (required)>'
/home/indiba3/.rvm/gems/ruby-2.1.8/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/indiba3/.rvm/gems/ruby-2.1.8/bin/ruby_executable_hooks:15:in `eval'
/home/indiba3/.rvm/gems/ruby-2.1.8/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => task_namespace:birthday_invitation_mail
(See full trace by running task with --trace)
So how may i slove this error and let the email to be sent to 500 person and if any email is wrong i may get the output in another log file........so pls help...........??
Fetch users in batches and then try to send mails.
mailer
def birthday_email
date = Date.today
Employee.where("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m')).where("age > 21").find_in_batches do |group|
sleep(5)
group.each { |emp| mail(to: emp.email, subject: 'Birthday Wishes') }
end
end
rake
EmployeeMailer.birthday_email.deliver!
I am trying to convert an uploaded video into multiple formats but I am getting an error
Video model:
class Video < ActiveRecord::Base
has_attached_file :video, {
preserve_files: true,
styles: {
ogg: { :processors => [:ogg_processor] },
},
url: '/tmp/paperclip/:rails_env/video/:style/:filename',
path: ':rails_root/public:url',
}
# paperclip:
validates :video, attachment_presence: true
validates_with AttachmentContentTypeValidator, attributes: :video, content_type: /\Avideo\/.*\Z/
validates_with AttachmentSizeValidator, attributes: :video, less_than: 150.megabytes
end
This variation of options didn't work either:
has_attached_file :video, {
preserve_files: true,
processors: [:ogg_processor],
styles: {
original: {},
},
url: '/tmp/paperclip/:rails_env/video/:style/:filename',
path: ':rails_root/public:url',
}
Processor:
# lib/paperclip_processors/ogg_processor.rb
module Paperclip
class OggProcessor < Processor
def make
output = Tempfile.new([File.basename(#file.path), '.ogv'])
parameters = '--max_size 1280x1280 --output :output :input'
Paperclip.run('ffmpeg2theora', parameters, output: File.expand_path(file.path), input: File.expand_path(output.path))
output
end
end
end
Error:
Paperclip::AdapterRegistry::NoHandlerError: No handler found for "public/tmp/videos/SampleVideo_720x480_30mb.mkv"
/home/vedant/.gem/ruby/2.2.4/gems/paperclip-4.3.7/lib/paperclip/io_adapters/registry.rb:19:in `handler_for'
/home/vedant/.gem/ruby/2.2.4/gems/paperclip-4.3.7/lib/paperclip/io_adapters/registry.rb:29:in `for'
/home/vedant/.gem/ruby/2.2.4/gems/paperclip-4.3.7/lib/paperclip/attachment.rb:98:in `assign'
/home/vedant/.gem/ruby/2.2.4/gems/paperclip-4.3.7/lib/paperclip/has_attached_file.rb:66:in `block in define_setter'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:54:in `public_send'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:35:in `each'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/core.rb:566:in `init_attributes'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/core.rb:281:in `initialize'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/inheritance.rb:61:in `new'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/inheritance.rb:61:in `new'
/home/vedant/.gem/ruby/2.2.4/gems/activerecord-4.2.5/lib/active_record/persistence.rb:50:in `create!'
/home/vedant/web/voggle/lib/tasks/dummy.rake:47:in `block (3 levels) in <top (required)>'
/home/vedant/web/voggle/lib/tasks/dummy.rake:46:in `each'
/home/vedant/web/voggle/lib/tasks/dummy.rake:46:in `block (2 levels) in <top (required)>'
/home/vedant/.gem/ruby/2.2.4/gems/airbrake-5.5.0/lib/airbrake/rake/task_ext.rb:19:in `execute'
/home/vedant/.gem/ruby/2.2.4/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => dummy:videos
(See full trace by running task with --trace)
Okay it was a very silly mistake.
I was sending a String instead of a File object. I just did File.new(video_file) and it worked.
It shows wrong number of arguments but I am passing 3 arguments
ScannerWorker.perform_async('bob1','bob2',5)
Here sidekiq worker code
class ScannerWorker
include Sidekiq::Worker
def perform(bob1, bob2, bob3)
puts bob1
end
end
sidekiq version:- 4.2.7
rails 4.2.6
Redis server v=3.0.7
Sidekiq Error:-
2017-01-03T06:29:43.007Z 9547 TID-itjjk WARN: ArgumentError: wrong number of arguments (given 0, expected 2..3)
2017-01-03T06:29:43.007Z 9547 TID-itjjk WARN: /home/smk/14.04/rails/projects/myappname/app/workers/scanner_worker.rb:5:in `test'
/home/smk/14.04/rails/projects/myappname/app/workers/scanner_worker.rb:5:in `perform'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:158:in `execute_job'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:138:in `block (4 levels) in process'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq.rb:36:in `block in <module:Sidekiq>'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:133:in `block (3 levels) in process'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:128:in `block in invoke'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/logging.rb:32:in `with_context'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:133:in `invoke'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:132:in `block (2 levels) in process'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:174:in `stats'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:131:in `block in process'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq.rb:35:in `block in <module:Sidekiq>'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:126:in `process'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:82:in `process_one'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:70:in `run'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/util.rb:17:in `watchdog'
/home/smk/14.04/rails/projects/myappname/vendor/bundle/gems/sidekiq-4.2.7/lib/sidekiq/util.rb:25:in `block in safe_thread'
You need to restart Sidekiq. Live code reloading only works with Sidekiq 4.2+ running Rails 5.0+.
Follow this steps
* Mention the sidekiq version in gemfile
* kill the sidekiq process and restart the sidekiq
You need to restart Sidekiq
To Start:
$ bundle exec sidekiq
To Run in the background:
$ bundle exec sidekiq -d -P tmp/sidekiq.pid -L log/sidekiq.log
where -d demonize, -P pid file, -L log file.
Stop:
$ bundle exec sidekiqctl stop tmp/sidekiq.pid 0
Sidekiq shut down gracefully.
where 0 is number of seconds to wait until Sidekiq exits.
worth noting. I've been working on a similar issue.
SomeWorker.perform_async(#user.id)
class SomeWorker
include Sidekiq::Worker
def perform(user_id)
puts "{user_id}"
end
end
unsure exactly why i was getting the arguments error. Maybe it was an because of an instance variable, maybe a rails bug.
Nevertheless, I receated the worker using
$rails g sidekiq:worker SomeWorker
and saw this *.
class SomeWorker
include Sidekiq::Worker
def perform(*args)
puts #some thing
end
end
by adding the astrix everything worked perfectly.
quick answer:
class SomeWorker
include Sidekiq::Worker
def perform(*user_id)
puts #some thing
end
end
I have a Classified Model where i use a after_create callback for checking keywords of a user and send email notification.
this email it is send by a Background Job using ActiveJobs and Sucker_punch as background driver.
I see in the logs 3 jobs are being queued:
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 8843b126-18fe-4cc1-b2f3-41141a199bcb) to SuckerPunch(mailers) with arguments: "NotificationMailer", "keyword_found", "deliver_now", gid://clasificados/Classified/233, gid://clasificados/User/1
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 591ce6eb-34d1-4381-93ea-4b708171996f) to SuckerPunch(mailers) with arguments: "NotificationMailer", "keyword_found", "deliver_now", gid://clasificados/Classified/234, gid://clasificados/User/1
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 3b1de0ea-f48d-41f2-be5a-8f5b2369b8ea) to SuckerPunch(mailers) with arguments: "NotificationMailer", "keyword_found", "deliver_now", gid://clasificados/Classified/235, gid://clasificados/User/1
but i only received 2 emails...
i see in logs errors like:
Terminating 6 actors...
Terminating task: type=:finalizer, meta={:method_name=>:__shutdown__}, status=:receiving
Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.`
Terminating task: type=:call, meta={:method_name=>:perform}, status=:callwait
Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.
Celluloid::PoolManager: async call `perform` aborted!
Celluloid::Task::TerminatedError: task was terminated
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:34:in `terminate'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `each'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `cleanup'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:329:in `shutdown'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:164:in `run'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:130:in `block in start'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/thread_handle.rb:13:in `block in initialize'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:32:in `block in get_thread'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `call'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `block in create'
Terminating task: type=:call, meta={:method_name=>:perform}, status=:callwait
Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.
Celluloid::PoolManager: async call `perform` aborted!
Celluloid::Task::TerminatedError: task was terminated
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:34:in `terminate'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `each'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `cleanup'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:329:in `shutdown'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:164:in `run'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor.rb:130:in `block in start'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/thread_handle.rb:13:in `block in initialize'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:32:in `block in get_thread'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `call'
/home/angel/.gem/ruby/2.2.2/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `block in create'
Terminating task: type=:finalizer, meta={:method_name=>:__shutdown__}, status=:receiving
Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.
Model:
class Classified < ActiveRecord::Base
after_create :find_matched_keywords
def find_matched_keywords
User.all.each do |u|
u.profile.keywords.scan(/[a-zA-Z\d]+/) do |k|
if self[:content].downcase.include?(k)
SendEmailJob.new.async.perform(self, u)
break
end
end
end
end
end
Job:
class SendEmailJob < ActiveJob::Base
include SuckerPunch::Job
queue_as :default
def perform(classified, user)
NotificationMailer.keyword_found(classified, user).deliver_later
end
end
any idea what could be happening?
thanks in advance :D
well, i changed to sidekiq...
problem solved.
This is my first time using stack overflow for a personal question and I have searched for an answer to my question, with no success, so please be patient with me if I have overlooked anything, and thank you in advance for your help.
I'm currently making an application using ruby on rails 4 version 4.1.1 (using RVM) and it seems that every time I enter any rake or rails command (such as rails server or rails console) in the command line, there is a 50/50 chance that it will work as planned, the rest of the time I get the following error message:
/Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:222:in `split': invalid byte sequence in UTF-8 (ArgumentError)
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:224:in `setup_environment'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:17:in `setup'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler.rb:120:in `setup'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:94:in `setup'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:124:in `check'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:131:in `<top (required)>'
from /Users/drobro/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from /Users/drobro/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /Users/drobro/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/rubygems-bundler-1.4.4/lib/rubygems_executable_plugin.rb:4:in `block in <top (required)>'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:50:in `call'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:50:in `block in run'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:49:in `each'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:49:in `run'
from /Users/drobro/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:10:in `<main>'
Now, I went to check the apparently faulty code in the runtime.rb and it looks like this:
def setup_environment
begin
ENV["BUNDLE_BIN_PATH"] = Bundler.rubygems.bin_path("bundler", "bundle", VERSION)
rescue Gem::GemNotFoundException
ENV["BUNDLE_BIN_PATH"] = File.expand_path("../../../bin/bundle", __FILE__)
end
# Set PATH
paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR)
paths.unshift "#{Bundler.bundle_path}/bin"
ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR)
# Set BUNDLE_GEMFILE
ENV["BUNDLE_GEMFILE"] = default_gemfile.to_s
# Set RUBYOPT
rubyopt = [ENV["RUBYOPT"]].compact
if rubyopt.empty? || rubyopt.first !~ /-rbundler\/setup/
rubyopt.unshift %|-rbundler/setup|
ENV["RUBYOPT"] = rubyopt.join(' ')
end
# Set RUBYLIB
rubylib = (ENV["RUBYLIB"] || "").split(File::PATH_SEPARATOR)
rubylib.unshift File.expand_path('../..', __FILE__)
ENV["RUBYLIB"] = rubylib.uniq.join(File::PATH_SEPARATOR)
end
at line 222, which is the line right beneath the # Set PATH comment, i.e. paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR). From what I understand, this is telling me that the argument to the split method, File::PATH_SEPARATOR, is invalid in UTF-8 encoding. I decided to throw in some puts statements around that code to check what was going on. So, right under # Set PATH, I typed:
puts "File::PATH_SEPARATOR is this: #{File::PATH_SEPARATOR}"
puts "This is the encoding: #{File::PATH_SEPARATOR.encoding}"
File::PATH_SEPARATOR.each_byte do |c|
puts "This is the ASCII value: #{c}"
end
ON THE TIMES WHEN A RAILS COMMAND DOES NOT WORK, the output to the terminal is:
File::PATH_SEPARATOR is this: :
This is the encoding: ASCII-8BIT
This is the ASCII value: 58
/Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:227:in `split': invalid byte sequence in UTF-8 (ArgumentError)
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:224:in `setup_environment'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler/runtime.rb:15:in `setup'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler.rb:120:in `setup'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:94:in `setup'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:124:in `check'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:131:in `<top (required)>'
from /Users/drobro/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from /Users/drobro/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /Users/drobro/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/rubygems-bundler-1.4.4/lib/rubygems_executable_plugin.rb:4:in `block in <top (required)>'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:50:in `call'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:50:in `block in run'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:49:in `each'
from /Users/drobro/.rvm/gems/ruby-2.1.2#global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:49:in `run'
from /Users/drobro/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:10:in `<main>'
AND ON THE TIMES WHEN A RAILS COMMAND DOES WORK, the output to the terminal is (this example is for the rails server command):
File::PATH_SEPARATOR is this: :
This is the encoding: ASCII-8BIT
This is the ASCII value: 58
File::PATH_SEPARATOR is this: :
This is the encoding: ASCII-8BIT
This is the ASCII value: 58
=> Booting WEBrick
=> Rails 4.1.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-07-08 17:36:40] INFO WEBrick 1.3.1
[2014-07-08 17:36:40] INFO ruby 2.1.2 (2014-05-08) [x86_64-darwin13.0]
[2014-07-08 17:36:40] INFO WEBrick::HTTPServer#start: pid=6447 port=3000
This is what worries me: the information returned is IDENTICAL in both cases. What's worse is that the encoding is ASCII-8BIT, which is more restrictive than UTF-8, and anyways the invalid character is supposedly just a colon... which should never cause any problems in either of those encodings right?? So I have 2 questions:
1) Why in the world am I getting this invalid utf-8 error?
2) Why does it only happen half the time despite the input being identical??
Thank you for helping, I'm at a loss here.
I managed to fix the problem by changing the line:
paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR)
to:
paths = (ENV["PATH"] || "").encode('UTF-8', :invalid => :replace).split(File::PATH_SEPARATOR)
My understanding is that this will replace an invalid UTF-8 byte sequence with (an equivalent??) one that is valid. However, this does not explain why the problem was happening just half the time, and that is what was really getting to me.
So, if anyone reads this and has any clue as to what was happening, please feel free to comment and let me know, it would be very much appreciated.