Defect #35421

Unhandled exception when a YAML syntax error is detected in configuration.yml

Added by Go MAEDA about 1 month ago. Updated 27 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Administration
Target version:5.0.0
Resolution:Fixed Affected version:

Description

Redmine will abort with Psych::SyntaxError during startup if a YAML syntax error in configuration.yml is detected.

/Users/somebody/.rbenv/versions/3.0.0/lib/ruby/3.0.0/psych.rb:456:in `parse': (<unknown>): did not find expected key while parsing a block mapping at line 11 column 1 (Psych::SyntaxError)
        from /Users/somebody/.rbenv/versions/3.0.0/lib/ruby/3.0.0/psych.rb:456:in `parse_stream'
        from /Users/somebody/.rbenv/versions/3.0.0/lib/ruby/3.0.0/psych.rb:390:in `parse'
        from /Users/somebody/.rbenv/versions/3.0.0/lib/ruby/3.0.0/psych.rb:280:in `load'
        from /path/to/redmine/lib/redmine/configuration.rb:95:in `load_from_yaml'
        from /path/to/redmine/lib/redmine/configuration.rb:45:in `load'
        from /path/to/redmine/lib/redmine/configuration.rb:76:in `[]'

Although the code at source:tags/4.2.1/lib/redmine/configuration.rb#L98 tries to catch the exception, the code never catches it because the rescue statement should handle Psych::SyntaxError instead of SyntaxError.

        rescue SyntaxError => e
          abort "A syntax error occurred when parsing your Redmine configuration file located at #{filename} with ERB:\n#{e.message}" 

35421.patch Magnifier (670 Bytes) Go MAEDA, 2021-06-17 07:26

35421-v2.patch Magnifier (683 Bytes) Go MAEDA, 2021-06-17 08:03

35421-v2.patch Magnifier (683 Bytes) Go MAEDA, 2021-06-22 10:56


Related issues

Related to Redmine - Defect #9748: Error about configuration.yml validness should mention fi... Closed

Associated revisions

Revision 21057
Added by Go MAEDA 27 days ago

Unhandled exception when a YAML syntax error is detected in configuration.yml (#35421).

Patch by Go MAEDA.

History

#1 Updated by Go MAEDA about 1 month ago

The attached patch fixes the issue.

#2 Updated by Go MAEDA about 1 month ago

Go MAEDA wrote:

Although the code at source:tags/4.2.1/lib/redmine/configuration.rb#L98 tries to catch the exception, the code never catches it because the rescue statement should handle Psych::SyntaxError instead of SyntaxError.

According to #9748 and #16878, the code that is intended to handle a YAML syntax error is not source:tags/4.2.1/lib/redmine/configuration.rb#L98 but source:tags/4.2.1/lib/redmine/configuration.rb#L96. So, the patch 35421.patch is wrong.

        rescue ArgumentError
          abort "Your Redmine configuration file located at #{filename} is not a valid YAML file and could not be loaded." 
        rescue SyntaxError => e
          abort "A syntax error occurred when parsing your Redmine configuration file located at #{filename} with ERB:\n#{e.message}" 
        end

Attaching an updated patch.

#3 Updated by Go MAEDA about 1 month ago

  • Related to Defect #9748: Error about configuration.yml validness should mention file path added

#4 Updated by Go MAEDA about 1 month ago

  • Target version set to 5.0.0

Setting the target version to 5.0.0.

#5 Updated by Go MAEDA about 1 month ago

Update the patch to display Exception#message. This is necessary for users to know where the syntax error occurred.

#6 Updated by Go MAEDA 27 days ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch.

Also available in: Atom PDF