NoMethodError: line_code_for_position
Summary
NoMethodError: line_code_for_position
occurs when I write some comments on a line of code.
Steps to reproduce
Write a comment on a line of code. This error occurs in some lines but not in all lines.
Expected behavior
The comment has to be saved without any error.
Actual behavior
Sometimes I got 500 errors.
Relevant logs and/or screenshots
Started POST "/xxx/xxx/notes" for 10.42.43.107 at 2017-02-09 05:30:14 +0000 Processing by Projects::NotesController#create as JSON
Parameters: {"utf8"=>"?", "authenticity_token"=>"VoOHF4NKWMDJsi2+fKush8pLQo37P43K2dgi0rpSMDzRkRxuNC8N0KDyTcqrQKPg2ywD5LEL1SSAF4N5JVzEMQ==", "view"=>"inline", "line_type"=>"new", "merge_request_diff_head_sha"=>"33db6bdad3e0f1328020b6e27b2e0fbbbdf2e122", "target_type"=>"merge_request", "target_id"=>"4589", "note"=>{"commit_id"=>"", "line_code"=>"45cb6d37cb9d777cf3add56e007f920b2b2d6220_0_5", "noteable_id"=>"4589", "noteable_type"=>"MergeRequest", "type"=>"DiffNote", "position"=>"{\"old_path\":\"XXX/XXX.cs\",\"new_path\":\"XXX/XXX.cs\",\"old_line\":null,\"new_line\":5,\"base_sha\":\"e10ff00bb6a4dc0d82d14eaa2c8a2ff73d16cc44\",\"start_sha\":\"e10ff00bb6a4dc0d82d14eaa2c8a2ff73d16cc44\",\"head_sha\":\"33db6bdad3e0f1328020b6e27b2e0fbbbdf2e122\"}", "note"=>"Hello, world!"}, "commit"=>"Comment", "namespace_id"=>"xxx", "project_id"=>"xxx"}
Completed 500 Internal Server Error in 45ms (ActiveRecord: 4.9ms)
NoMethodError (undefined method `line_code_for_position' for nil:NilClass):
lib/gitlab/diff/position.rb:136:in `line_code'
app/models/diff_note.rb:152:in `set_line_code'
app/services/notes/create_service.rb:37:in `execute'
app/controllers/projects/notes_controller.rb:27:in `create'
lib/gitlab/middleware/multipart.rb:93:in `call'
lib/gitlab/request_profiler/middleware.rb:15:in `call'
lib/gitlab/middleware/go.rb:16:in `call'
lib/gitlab/middleware/readonly_geo.rb:29:in `call'
Output of checks
Results of GitLab application Check
Too long to paste but there's no problem.
Redis version >= 2.8.0? ... yes
Ruby version >= 2.1.0 ? ... yes (2.3.3)
Your git bin path is "/opt/gitlab/embedded/bin/git
Git version >= 2.7.3 ? ... yes (2.10.2)
Active users: 38
Checking GitLab ... Finished
Results of GitLab environment info
System information
System: Ubuntu 14.04
Current User: git
Using RVM: no
Ruby Version: 2.3.3p222
Gem Version: 2.6.6
Bundler Version:1.13.7
Rake Version: 10.5.0
Sidekiq Version:4.2.7
GitLab information
Version: 8.16.4-ee
Revision: 93daa28
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 9.2.18
URL: http://git.k.nexon.com
HTTP Clone URL: http://git.k.nexon.com/some-group/some-project.git
SSH Clone URL: git@git.k.nexon.com:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 4.1.1
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks/
Git: /opt/gitlab/embedded/bin/git
Possible fixes
I have no idea.