Skip to content

Commit

Permalink
Report a more explicit error on indentation issues
Browse files Browse the repository at this point in the history
When a template parameter is accidentially unindented, the stack
attributes become empty. This resulted in:

```
lib/stack_master/config.rb:123:in `block (2 levels) in load_stacks':
undefined method `[]' for nil:NilClass (NoMethodError)

          stack_attributes['allowed_accounts'] = attributes['allowed_accounts'] if attributes['allowed_accounts']
```

Now it will report a ConfigParseError with a more specific message.
  • Loading branch information
viraptor committed Mar 1, 2024
1 parent 5ad2eb3 commit 50a58aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/stack_master/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def load_stacks(stacks)
stacks.each do |region, stacks_for_region|
region = Utils.underscore_to_hyphen(region)
stacks_for_region.each do |stack_name, attributes|
raise ConfigParseError.new("Entry for stack #{stack_name} has no attributes") if attributes.nil?

stack_name = Utils.underscore_to_hyphen(stack_name)
stack_attributes = build_stack_defaults(region).deeper_merge!(attributes).merge(
'region' => region,
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/stack_master_wrong_indent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
stacks:
us-east-1:
myapp_vpc:
template: myapp_vpc.json
10 changes: 10 additions & 0 deletions spec/stack_master/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
end
end

it "gives explicit error on badly indented entries" do
begin
orig_dir = Dir.pwd
Dir.chdir './spec/fixtures/'
expect { StackMaster::Config.load!('stack_master_wrong_indent.yml') }.to raise_error StackMaster::Config::ConfigParseError
ensure
Dir.chdir orig_dir
end
end

it "searches up the tree for stack master yaml" do
begin
orig_dir = Dir.pwd
Expand Down

0 comments on commit 50a58aa

Please sign in to comment.