Home>

Always I am indebted.
I'm currently creating an application like SNS
I wanted to deploy to the production environment once, created a bucket in S3, and when I accessed the deployment destination, the following error occurred.

When reading the error log, it seems that the cause is "using tabs for the yal file", which will be described later, but of course visually

https://jsonformatter.org/yaml-formatter

After some trial and error using several such sites, the results did not change.

Message displayed to the access destination after deployment

Application error
An error occurred in the application and your page could not be served. If i am the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

I tried heroku logs --tail

/app/vendor/bundle/ruby/2.7.0/gems/activestorage-6.0.3.4/lib/active_storage/engine.rb:113:in `rescue in block (2 levels) in<class: Engine>': YAML syntax error occurred while parsing /app/config/storage.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)
(<unknown>): did not find expected key while parsing a block mapping at line 1 column 1 (Psych :: SyntaxError)


I tried heroku run rails c

curred while parsing /app/config/storage.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)

With this message, I hypothesized that there might be something wrong with the yml file.

Corresponding source code
storage.yml
test: test:
 service: Disk
 root:<% = Rails.root.join ("tmp/storage")%>
local:
 service: Disk
 root:<% = Rails.root.join ("storage")%>
amazon:
 service: S3
 access_key_id:<% = ENV ['AWS_ACCESS_KEY_ID']%>
 secret_access_key:<% = ENV ['AWS_SECRET_ACCESS_KEY']%>
 region: ap-northeast-1
 bucket: rank-top-32010
databese.yml
default:&default
  adapter: mysql2
  encoding: utf8
  pool:<% = ENV.fetch ("RAILS_MAX_THREADS") {5}%>
  username: root
  password: password:
  socket: /tmp/mysql.sock
development:
<<: * default
  database: rank_top_development
test: test:
<<: * default
  database: rank_top_test
production:
<<: * default
  database: rank_top_production
  username: rank_top
  password:<% = ENV ['RANK_TOP_DATABASE_PASSWORD']%>
What I tried

Translated message from heroku run rails c
White space has an effect. It was written, so I paid close attention to that part and corrected it.
Also, referring to the ones deployed in the past, there was a part where the order was changed, so correct it in the same way as the past ones

The result did not change.

I checked if there is a description of gem "aws-sdk-s3", require: false.

I'm a beginner so it may be wrong,
Since the message seems to have a problem on the first line, is there a case where the problem occurred before the yml file and it appeared in the message like this?

  • Answer # 1

    at line 1 column 1

    So

    Maybe your editor has the BOM inserted at the beginning
    I think the Rails side has recognized it as a zero-width space.

    As a countermeasure, the specific method will differ depending on your environment.
    I think it's a good idea to delete the BOM in some way.