Skip to content

Fix config.yml template indentation #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2023
Merged

Conversation

allcentury
Copy link
Contributor

@allcentury allcentury commented Dec 29, 2023

Prior to this change, if all #'s are removed from the config template you're left with is a yaml file that solid_queue can't parse.

bundle exec rake solid_queue:start
rake aborted!
YAML syntax error occurred while parsing
/project/config/solid_queue.yml. Please note
that YAML must be consistently indented using spaces. Tabs are not
allowed. Error: (<unknown>): did not find expected key while parsing a
block mapping at line 1 column 1

reproducable in this repo via (remove comments first). After fix:

ActiveSupport::ConfigurationFile.parse("./lib/generators/solid_queue/install/templates/config.yml")["development"]
=> {"batch_size"=>10, "dispatchers"=>[{"polling_interval"=>1,
"batch_size"=>500}], "workers"=>[{"queues"=>"*", "threads"=>5,
"processes"=>1, "polling_interval"=>0.1}]}

@rosa
Copy link
Member

rosa commented Dec 29, 2023

Oh! I can't reproduce this one. Is it possible you left the first line:

#default: &default

commented-out?

@allcentury
Copy link
Contributor Author

allcentury commented Dec 29, 2023

I see this file:

#default: &default
#   dispatchers:
#     - polling_interval: 1
#       batch_size: 500
#   workers:
#     - queues: "*"
#       threads: 5
#       processes: 1
#       polling_interval: 0.1
#
# development:
#  <<: *default
#
# test:
#  <<: *default
#
# production:
#  <<: *default

If I remove the # - I'm left with:

default: &default
   dispatchers:
     - polling_interval: 1
       batch_size: 500
   workers:
     - queues: "*"
       threads: 5
       processes: 1
       polling_interval: 0.1

 development:
  <<: *default

 test:
  <<: *default

 production:
  <<: *default

Which fails with:

ActiveSupport::ConfigurationFile.parse("./lib/generators/solid_queue/install/templates/config.yml")
/Users/anthonyross/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.1.0/lib/active_support/configuration_file.rb:29:in `rescue in parse': YAML syntax error occurred while parsing ./lib/generators/solid_queue/install/templates/config.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1 (RuntimeError)

So that's problem 1.

Problem 2 is that the Rails.env keys (development, test, etc) still have a leading space when they should have zero.

Problem 3 is that the default indentation has one extra space (3 instead of 2)

@rosa
Copy link
Member

rosa commented Dec 29, 2023

Oh! I just realised the real issue is the missing space before default, in #default. My editor was handling that correctly via toggle comment shortcut, so I didn't see the problem, but I think the change should be this:

diff --git a/lib/generators/solid_queue/install/templates/config.yml b/lib/generators/solid_queue/install/templates/config.yml
index 9c1856a..7270d0a 100644
--- a/lib/generators/solid_queue/install/templates/config.yml
+++ b/lib/generators/solid_queue/install/templates/config.yml
@@ -1,4 +1,4 @@
-#default: &default
+# default: &default
 #   dispatchers:
 #     - polling_interval: 1
 #       batch_size: 500

@allcentury
Copy link
Contributor Author

@rosa ya. Looks like adding that one space back allows ActiveSupport::ConfigurationFile.parse("./lib/generators/solid_queue/install/templates/config.yml") to work.

It still shows an extra leading space for me when I use https://github.com/tpope/vim-commentary but it's easy enough for me to remove. Which patch do you prefer?

Screenshot 2023-12-29 at 3 27 56 PM

@rosa
Copy link
Member

rosa commented Dec 30, 2023

I prefer the second one; I think it looks nicer with the space after #.

Prior to this change, if all #'s are removed from the config template you're left with a yaml
file that solid_queue can't parse.

```
bundle exec rake solid_queue:start
rake aborted!
YAML syntax error occurred while parsing
/Users/anthonyross/projects/mint/config/solid_queue.yml. Please note
that YAML must be consistently indented using spaces. Tabs are not
allowed. Error: (<unknown>): did not find expected key while parsing a
block mapping at line 1 column 1
```

reproducable in this repo via (remove comments first).  After fix:

```
ActiveSupport::ConfigurationFile.parse("./lib/generators/solid_queue/install/templates/config.yml")["development"]
=> {"batch_size"=>10, "dispatchers"=>[{"polling_interval"=>1,
"batch_size"=>500}], "workers"=>[{"queues"=>"*", "threads"=>5,
"processes"=>1, "polling_interval"=>0.1}]}
```
Copy link
Member

@rosa rosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much!

@rosa rosa merged commit 9777594 into rails:main Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants