Opsworks deployment doesn't have node[:deploy] - docker

My opsworks deployment's node doesnt have [:deploy] object
This is my Chef script
if node[:deploy] === nil
Chef::Log.info("No deployment..")
node[:deploy].each do |app, deploy|
Chef::Log.info("deploy -#{ app }-")
end
elsif
# never goes here
end
i got this error on line 4
undefined method `each' for nil:NilClass (NoMethodError)

firstly, i will advise you to read What does the “===” operator do in Ruby?.
i have a feeling that you meant to use ==, rather than ===. change your triple equal operator to double equal operator and give it a try...
you can use #nil? if you want to make it more readable (depending on your ruby version). change
if node[:deploy] === nil
to
node[:deploy].nil?

Related

Rails 5: Error when removed quiet_assets_path from development.rb

I have been trying to upgrade my app from Rails 4 to Rails 5. In my Rails 4 version I have quiet_assets_path set but in Rails 5 it is not required. But when I removed that tried to start the server I am getting the following error,
> ruby-2.2.2/gems/rack-mini-profiler-0.10.2/lib/mini_profiler_rails/railtie.rb:93:in
> `>': comparison of Fixnum with nil failed (ArgumentError) from
> /Users/Admin/.rvm/gems/ruby-2.2.2/gems/rack-mini-profiler-0.10.2/lib/mini_profiler_rails/railtie.rb:93:in
> `block in <class:Railtie>'
Can someone help me with this?
Edit:
Following is my rack_profiler.rb,
if Rails.env.development? || Rails.env.production?
require 'rack-mini-profiler'
# initialization is skipped so trigger it
Rack::MiniProfilerRails.initialize!(Rails.application)
Rack::MiniProfiler.config.skip_schema_queries = true
Rack::MiniProfiler.config.skip_paths += %w(/admin/sidekiq)
Rails.application.middleware.delete(Rack::MiniProfiler)
Rails.application.middleware.insert_after(Rack::Deflater, Rack::MiniProfiler)
end
When I comment the delete line then server is starting but if the line uncommented then the server breaks.
thanks for the update. First of all, do you use Rack::Deflater middleware in development environment too?
I think this issue might help you. It basically says that in Rails all delete middleware operations are issued at the end. You can use the swap method as described in the above issue.
If you search the repo issues for "Deflater" you'll find a lot of results, but I believe the above contains your fix.

Ruby error evaluating function `font-url`: undefined method `path_to_asset' for nil:NilClass

I'm new to Ruby and Rails. I've implemented a module to allow me to manually compile LESS to CSS for my project to avoid using Sprockets, as it doesn't allow me to compile different LESS for each user.
When compiling LESS I randomly get the following error about 40% of the time. 60% of the time the LESS compiles correctly.
error evaluating function `font-url`: undefined method `path_to_asset' for nil:NilClass
What could be causing this, and why is it random?
Cheers,
-JC
Update:
Added a code sample:
# Prepare the body of the file.
body = File.read(#app_file_name_full)
body = ERB.new(body).result(binding) # Bind to the #instance variables in this module.
# Parse with LESS.
begin
body = Less::Parser.new({
paths: [#assets_path, "/usr/local/share/gems/gems/twitter-bootstrap-rails-3.2.2/vendor/toolkit/"],
filename: #final_file_name,
compress: true
}).parse(body).to_css
rescue Exception => err
puts "LESS PARSING FAILED! ", err.message
body = nil
end

Windows, Ec2ServerCreate - Cannot set JSON attributes when running knife from Rails application

I am able to launch new instance at AWS from Ruby on Rails application (Chef::Knife::Ec2ServerCreate.new()). Works fine till I try to set JSON attributes. When I set them from command line and invoke knife.bat, it works.
Looking at ec2_server_create shows that command line option --json-attributes is mapped to symbol :json_attributes. I tried to set it using following code:
Chef::Config[:knife][:json_attributes] = "{'NodeName' : 'Node001'}"
and I get error:TypeError (no implicit conversion of Symbol into Integer):
As soon as I comment this single line, instance is created, registered with chef server and recipe is running.
Any suggestion how to set json attributes of first chef-client run?
PS
Sample code shows constant value for attribute, but actual value would be dynamically created.
Error message and code line where error occurs:
/chef/knife/core/bootstrap_context.rb:188:in `[]=': no implicit conversion of Symbol into Integer (TypeError)
Looking into source you can find:
def first_boot
(#config[:first_boot_attributes] || {}).tap do |attributes|
if #config[:policy_name] && #config[:policy_group]
attributes[:policy_name] = #config[:policy_name]
attributes[:policy_group] = #config[:policy_group]
else
attributes[:run_list] = #run_list #THIS LINE CAUSES EXCEPTION
end
attributes.merge!(:tags => #config[:tags]) if #config[:tags] && !#config[:tags].empty?
end
end
I set run list.
The issue is that json_attributes needs to be a hash, not a string. It isn't the #run_list that is failing, it is "{'NodeName' : 'Node001'}"[:run_list] which when you see in on place is probably a bit clearer.

How to Calculate Nothing - Nil on Rails

Rails 4, Spree 2.1
The Issue:
Adding an item to cart with the Spree Flexi Variants engraving calculator, I get an error:
undefined method `value' for nil:NilClass
Is this line in my engraving calculator model causing this error?
def compute(product_customization, variant=nil)
return 0 unless valid_configuration? product_customization
# expecting only one CustomizedProductOption
opt = product_customization.customized_product_options.detect {|cpo| cpo.customizable_product_option.name == "inscription" } rescue ''
opt.value.length * (preferred_price_per_letter || 0)
end
def valid_configuration?(product_customization)
true
end
And as for the value method, any ideas on that?
I've tried defining value but nothing seems to work. I have another calculator called amount times contant. This is setup pretty much the same way; however, this one works. Getting kind of confused and way past my deadline.
Here is the github repo with the branch that I am using: https://github.com/jsqu99/spree_flexi_variants/tree/spree-2-1-wip
Trace:
NoMethodError (undefined method `value' for nil:NilClass)
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/calculator/engraving.rb:29:in `compute'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/product_customization.rb:11:in `price'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `block in add_to_line_item'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `map'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `add_to_line_item'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:7:in `add'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:36:in `attempt_cart_add'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:17:in `block in populate'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:16:in `each'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:16:in `populate'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/controllers/spree/orders_controller_decorator.rb:18:in `populate'
The source code you pointed to on github contains a different definition of compute as follows:
which is consistent with your stack trace, since line 29 of engraving.rb involves an invocation of value. I'm not familiar with spree, but based on this code, the detect call is returning nil.

NoMethodError in Rails 2.3.2 app

I have this strange error in one of my rails 2.3.2 application.
NoMethodError in Timesheet#index
undefined method '>=' for nil:NilClass
Extracted source (around line #27):
24: for alog in act_logs
25: if alog.user_id == session[:user_id].id
27: if(alog.log_date>=#dt.beginning_of_week()&& alog.log_date<=#dt.end_of_week())
As far as I can guess, I think either alog.log_date or #dt.beginning_of_week is nil. But a quick inspection just before line #27(inspection not included here) shows the following values:
#alog.log_date
Wed, 09 Feb 2011
##dt.beginning_of_week()
Mon, 10 Oct 2011
Now if none of these values are nil why do I get this undefined method >= for nil:NilClass error on line #27. If you guys are wondering why I call this strange....its because
1. If I use == operator, everything's ok. Other operators like >, < generate the same error.
2. This same code is working on another machine.
I don't think that it's a code problem here. Has it got something to do with the Ruby or may be Rails installation problem?
The error means precisely that alog.log_date is nil. alog.log_date>=#dt.beginning_of_week() is the same as alog.log_date.>=(#dt.beginning_of_week()), i.e. >= is just a method call (with some syntactic sugar). If the latter would be nil, you'd instead get something like this:
ArgumentError: comparison of Time with nil failed
You could add an existence check for the date in the beginning of the line:
if (alog.log_date && alog.log_date >= #dt.beginning_of_week() && alog.log_date<=#dt.end_of_week())
However, if you think that date should never be nil you might want to add a default value and/or a presence validation for the field.
Good technique to catch such a bug is to attach debugger
or simplier one is to write values to log, you should just put:
Rails.logger.info( variable_to_log )
before error line
PS
it works with equality operator '==' as nil object has this method
your comparison operator exists for integer class only

Resources