Defect #13692
closedwarning: already initialized constant on Ruby 1.8.7
0%
Description
When running the following command (either from the command line or git's post-receive hook) output generated produces warnings.
Commandrails runner "Repository.fetch_changesets" -e production
Warnings/usr/lib64/ruby/gems/1.8/gems/coderay-1.0.9/lib/coderay/helpers/file_type.rb:19: warning: already initialized constant UnknownFileType
/usr/lib64/ruby/gems/1.8/gems/coderay-1.0.9/lib/coderay/helpers/file_type.rb:126: warning: already initialized constant TypeFromExt
/usr/lib64/ruby/gems/1.8/gems/coderay-1.0.9/lib/coderay/helpers/file_type.rb:132: warning: already initialized constant TypeFromShebang
/usr/lib64/ruby/gems/1.8/gems/coderay-1.0.9/lib/coderay/helpers/file_type.rb:138: warning: already initialized constant TypeFromName
We're running redmine via passenger, and almost exclusively calling this script from gits post-receive hook. No functionality is broken, it's just generating warning output in the developers git bash when they push and trigger the script, which is causing a little bit of panic.
We upgraded directly from 2.1.6 so I do not know if this affected 2.2.x
       Updated by Peter Panther over 12 years ago
      Updated by Peter Panther over 12 years ago
      
    
    Have the same Issue with Version 2.3.1
Every runner-scripts produces warnings. The Apache log is is also flooded with these messages .....
/var/lib/gems/1.8/gems/coderay-1.0.8/lib/coderay/helpers/file_type.rb:19: warning: already initialized constant UnknownFileType /var/lib/gems/1.8/gems/coderay-1.0.8/lib/coderay/helpers/file_type.rb:126: warning: already initialized constant TypeFromExt /var/lib/gems/1.8/gems/coderay-1.0.8/lib/coderay/helpers/file_type.rb:132: warning: already initialized constant TypeFromShebang /var/lib/gems/1.8/gems/coderay-1.0.8/lib/coderay/helpers/file_type.rb:138: warning: already initialized constant TypeFromName
       Updated by Toshi MARUYAMA over 12 years ago
      Updated by Toshi MARUYAMA over 12 years ago
      
    
    - Subject changed from Updating to warning: already initialized constant
       Updated by xilong pei over 12 years ago
      Updated by xilong pei over 12 years ago
      
    
    My redmine, http://elastos.org/project/ has the same Issue.
Environment: Redmine version 2.0.3.stable Ruby version 1.8.7 (x86_64-linux) Rails version 3.2.6 Environment production Database adapter MySQL Redmine plugins: no plugin installed
       Updated by Sen Haerens over 12 years ago
      Updated by Sen Haerens over 12 years ago
      
    
    Same issue in 2.3.1
RAILS_ENV=production ./script/about /usr/lib/ruby/gems/1.8/gems/coderay-1.0.9/lib/coderay/helpers/file_type.rb:19: warning: already initialized constant UnknownFileType /usr/lib/ruby/gems/1.8/gems/coderay-1.0.9/lib/coderay/helpers/file_type.rb:126: warning: already initialized constant TypeFromExt /usr/lib/ruby/gems/1.8/gems/coderay-1.0.9/lib/coderay/helpers/file_type.rb:132: warning: already initialized constant TypeFromShebang /usr/lib/ruby/gems/1.8/gems/coderay-1.0.9/lib/coderay/helpers/file_type.rb:138: warning: already initialized constant TypeFromName Environment: Redmine version 2.3.1.stable.11903 Ruby version 1.8.7 (i686-linux) Rails version 3.2.13 Environment production Database adapter MySQL Redmine plugins: no plugin installed
       Updated by Nicolas Bouthors over 12 years ago
      Updated by Nicolas Bouthors over 12 years ago
      
    
    Hi all,
I had the same issue and I could fix it by commenting the line 36
require 'coderay/helpers/file_type'in
redmine/syntax_highlighting.rb.
	It seems to me that this combination of libs causes a include-loop (coderay auto loads syntax_highlighting).
Syntax highlight still works after ;)
       Updated by Toshi MARUYAMA over 12 years ago
      Updated by Toshi MARUYAMA over 12 years ago
      
    
    - Related to Defect #11089: UTF-8 encoding not showing correctly when looking highlighted php file contents added
       Updated by Toshi MARUYAMA over 12 years ago
      Updated by Toshi MARUYAMA over 12 years ago
      
    
    - Related to deleted (Defect #11089: UTF-8 encoding not showing correctly when looking highlighted php file contents)
       Updated by Toshi MARUYAMA over 12 years ago
      Updated by Toshi MARUYAMA over 12 years ago
      
    
    - Subject changed from warning: already initialized constant to warning: already initialized constant on Ruby 1.8.7
       Updated by Toshi MARUYAMA over 12 years ago
      Updated by Toshi MARUYAMA over 12 years ago
      
    
    - Target version changed from 2.4.0 to 2.3.2
       Updated by Toshi MARUYAMA over 12 years ago
      Updated by Toshi MARUYAMA over 12 years ago
      
    
    - Status changed from New to Closed
- Resolution set to Fixed
       Updated by Bert Fraterman almost 12 years ago
      Updated by Bert Fraterman almost 12 years ago
      
    
    We're running ruby 2.0.0, but the fix in r11925 causes a problem in displaying code files for us. We're getting a 500 error when trying to view file from the repository. Details:
Started GET "/projects/apps/repository/entry/trunk/code/Form1.cs" for 10.0.0.150 at 2013-11-08 10:41:35 +0100
Processing by RepositoriesController#entry as HTML
  Parameters: {"id"=>"apps", "path"=>"trunk/code/Form1.cs"}
  Current user: b.fraterman (id=11)
  Rendered repositories/_navigation.html.erb (3.1ms)
  Rendered repositories/_breadcrumbs.html.erb (1.9ms)
  Rendered repositories/_link_to_functions.html.erb (2.2ms)
  Rendered common/_file.html.erb (2.8ms)
  Rendered repositories/entry.html.erb within layouts/base (11.3ms)
Completed 500 Internal Server Error in 175ms
ActionView::Template::Error (uninitialized constant CodeRay::FileType):
    2: <table class="filecontent syntaxhl">
    3: <tbody>
    4: <% line_num = 1 %>
    5: <% syntax_highlight_lines(filename, Redmine::CodesetUtil.to_utf8_by_setting(content)).each do |line| %>
    6:   <tr>
    7:     <th class="line-num" id="L<%= line_num %>">
    8:       <a href="#L<%= line_num %>"><%= line_num %></a>
  lib/redmine/syntax_highlighting.rb:41:in `highlight_by_filename'
  lib/redmine/syntax_highlighting.rb:23:in `highlight_by_filename'
  app/helpers/application_helper.rb:394:in `syntax_highlight'
  app/helpers/application_helper.rb:389:in `syntax_highlight_lines'
  app/views/common/_file.html.erb:5:in `_app_views_common__file_html_erb___3771560638950630625_70345913460960'
  app/views/repositories/entry.html.erb:11:in `_app_views_repositories_entry_html_erb___25072457751040657_70345912345220'
	With 
require 'coderay/helpers/file_type'
everything works as expected.
       Updated by Toshi MARUYAMA almost 12 years ago
      Updated by Toshi MARUYAMA almost 12 years ago
      
    
    Bert Fraterman wrote:
We're running ruby 2.0.0, but the fix in r11925 causes a problem in displaying code files for us. We're getting a 500 error when trying to view file from the repository. Details:
[...]
With
[...]
everything works as expected.
I cannot reproduce on trunk r12297.
Started GET "/projects/redmine-bb-all/repository/entry/app/models/attachment.rb" for 127.0.0.1 at 2013-11-19 02:06:50 +0900
Processing by RepositoriesController#entry as HTML
  Parameters: {"id"=>"redmine-bb-all", "path"=>"app/models/attachment.rb"}
  Current user: anonymous
  Rendered repositories/_navigation.html.erb (424.2ms)
  Rendered repositories/_breadcrumbs.html.erb (3.7ms)
  Rendered repositories/_link_to_functions.html.erb (4.1ms)
  Rendered common/_file.html.erb (214.1ms)
  Rendered repositories/entry.html.erb within layouts/base (673.5ms)
Completed 200 OK in 1593.9ms (Views: 708.3ms | ActiveRecord: 5.8ms)
$ ruby --version ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]