GitLab UI not reporting stderr with pre-receive custom_hooks
Summary
I have a pre-receive custom hook installed on my GitLab repo, the enforces a particular commit pattern, eg "JIRA-ID: message" I get a 500 Internal Server error when committing a change in the GitLab UI (by editing a file in the browser and committing changes from there), and a "Something went wrong with merge" error when clicking Merge button in a merge request, if the commit message does not meet the requirements.
Steps to reproduce
- Create a repo
- Click the README file in the files list, and click to Edit the contents. Make a random change to the text.
- Leave the Commit message as it is, eg. "Update README.md" so that it doesn't meet the requirements enforced by the pre-receive hook
- Click "Commit changes"
- You get a 500 Whoops something went wrong on our end
OR
- Create a merge request from a branch that has changes.
- In the Merge Request screen in GitLab, modify the commit message so that it doesn't meet the requirements enforced by the pre-receive hook
- Click the Merge button to merge
- You get a message next to the Merge button "Something went wrong with merge". The page refreshes after 10 seconds and the message disappears. The same happens if you click Merge again.
The pre-receive hook writes the message that is supposed to inform the user that their commit message doesn't meet the requirements to stderr. I would expect this text to be relayed on the GitLab UI web page rather than a 500 server error or a simple "Something went wrong with merge" error.
production.log output for 500 error in the GitLab UI:
Started POST "/api/v4/internal/allowed" for 127.0.0.1 at 2018-11-09 20:58:42 +0000
Completed 500 Internal Server Error in 458ms (ActiveRecord: 5.2ms | Elasticsearch: 0.0ms)
RuntimeError (can't modify frozen String):
lib/gitlab/utils.rb:32:in `nlbr'
lib/gitlab/git/pre_receive_error.rb:17:in `nlbr'
lib/gitlab/git/pre_receive_error.rb:9:in `initialize'
lib/gitlab/gitaly_client/operation_service.rb:266:in `exception'
lib/gitlab/gitaly_client/operation_service.rb:266:in `raise'
▽
lib/gitlab/gitaly_client/operation_service.rb:266:in `user_commit_files'
lib/gitlab/git/repository.rb:792:in `block in multi_action'
lib/gitlab/git/repository.rb:862:in `wrapped_gitaly_errors'
lib/gitlab/git/repository.rb:791:in `multi_action'
app/models/repository.rb:818:in `block in multi_action'
app/models/repository.rb:801:in `with_cache_hooks'
app/models/repository.rb:818:in `multi_action'
app/models/repository.rb:791:in `update_file'
app/services/files/update_service.rb:6:in `create_commit!'
app/services/commits/create_service.rb:21:in `execute'
app/controllers/concerns/creates_commit.rb:25:in `create_commit'
app/controllers/projects/blob_controller.rb:65:in `update'
lib/gitlab/i18n.rb:53:in `with_locale'
lib/gitlab/i18n.rb:59:in `with_user_locale'
app/controllers/application_controller.rb:432:in `set_locale'
lib/gitlab/middleware/multipart.rb:101:in `call'
lib/gitlab/request_profiler/middleware.rb:14:in `call'
ee/lib/gitlab/jira/middleware.rb:15:in `call'
lib/gitlab/middleware/go.rb:17:in `call'
lib/gitlab/etag_caching/middleware.rb:11:in `call'
lib/gitlab/middleware/read_only/controller.rb:40:in `call'
lib/gitlab/middleware/read_only.rb:16:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/request_context.rb:18:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:27:in `call'
lib/gitlab/middleware/release_env.rb:10:in `call'
Error in log when doing merge request:
MergeService ERROR: core/server!9 - can't modify frozen String
Expand for output related to GitLab environment info
System information System: Proxy: no Current User: git Using RVM: no Ruby Version: 2.4.5p335 Gem Version: 2.7.6 Bundler Version:1.16.2 Rake Version: 12.3.1 Redis Version: 3.2.12 Git Version: 2.18.1 Sidekiq Version:5.2.1 Go Version: unknown
GitLab information Version: 11.4.5-ee Revision: bf6db46 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql DB Version: 9.6.8 URL: https://gitlab.red61.com HTTP Clone URL: https://gitlab.red61.com/some-group/some-project.git SSH Clone URL: git@gitlab.red61.com:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers:
GitLab Shell Version: 8.3.3 Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git
Expand for output related to the GitLab application check
Checking GitLab Shell ...
GitLab Shell version >= 8.3.3 ? ... OK (8.3.3) Repo base directory exists? default... yes Repo storage directories are symlinks? default... no Repo paths owned by git:root, or git:git? default... yes Repo paths access is drwxrws---? default... yes hooks directories in repos are links: ... 2/6 ... ok 2/7 ... ok 8/8 ... ok 8/9 ... ok 8/10 ... ok 2/12 ... ok 2/13 ... ok 2/14 ... ok 2/15 ... ok 8/16 ... ok 17/17 ... ok 2/19 ... ok 17/20 ... ok 2/21 ... ok 17/22 ... ok 2/23 ... ok 2/24 ... ok 2/25 ... ok 2/26 ... ok 16/27 ... ok 17/28 ... ok 2/29 ... ok 17/30 ... ok 17/31 ... ok 17/32 ... ok 17/33 ... ok 17/34 ... ok 17/35 ... ok 17/36 ... ok 17/37 ... ok 17/38 ... ok 17/39 ... ok 2/41 ... ok 17/42 ... ok 16/43 ... ok 17/44 ... ok 17/45 ... ok 17/46 ... ok 17/47 ... ok 17/48 ... ok 2/49 ... ok 17/50 ... ok 2/51 ... ok 17/52 ... ok 17/53 ... ok 20/54 ... ok 20/55 ... ok 20/56 ... ok 17/58 ... ok 20/59 ... ok 20/60 ... ok 20/61 ... ok 20/62 ... ok 21/64 ... ok 17/66 ... ok 20/67 ... ok 2/68 ... ok 17/69 ... repository is empty 2/70 ... ok 17/71 ... ok 22/72 ... ok 17/73 ... ok 17/74 ... ok 17/75 ... ok 2/76 ... ok 2/77 ... ok 8/78 ... ok 2/79 ... ok 17/81 ... ok 8/82 ... ok 20/83 ... ok 2/84 ... ok 8/85 ... ok 4/86 ... ok 17/87 ... ok 2/89 ... ok 2/90 ... ok 4/91 ... repository is empty Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Redis available via internal API: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Reply by email is disabled in config/gitlab.yml Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 2/6 ... yes 2/7 ... yes 8/8 ... yes 8/9 ... yes 8/10 ... yes 2/12 ... yes 2/13 ... yes 2/14 ... yes 2/15 ... yes 8/16 ... yes 17/17 ... yes 2/19 ... yes 17/20 ... yes 2/21 ... yes 17/22 ... yes 2/23 ... yes 2/24 ... yes 2/25 ... yes 2/26 ... yes 16/27 ... yes 17/28 ... yes 2/29 ... yes 17/30 ... yes 17/31 ... yes 17/32 ... yes 17/33 ... yes 17/34 ... yes 17/35 ... yes 17/36 ... yes 17/37 ... yes 17/38 ... yes 17/39 ... yes 2/41 ... yes 17/42 ... yes 16/43 ... yes 17/44 ... yes 17/45 ... yes 17/46 ... yes 17/47 ... yes 17/48 ... yes 2/49 ... yes 17/50 ... yes 2/51 ... yes 17/52 ... yes 17/53 ... yes 20/54 ... yes 20/55 ... yes 20/56 ... yes 17/58 ... yes 20/59 ... yes 20/60 ... yes 20/61 ... yes 20/62 ... yes 21/64 ... yes 17/66 ... yes 20/67 ... yes 2/68 ... yes 17/69 ... yes 2/70 ... yes 17/71 ... yes 22/72 ... yes 17/73 ... yes 17/74 ... yes 17/75 ... yes 2/76 ... yes 2/77 ... yes 8/78 ... yes 2/79 ... yes 17/81 ... yes 8/82 ... yes 20/83 ... yes 2/84 ... yes 8/85 ... yes 4/86 ... yes 17/87 ... yes 2/89 ... yes 2/90 ... yes 4/91 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.5 ? ... yes (2.4.5) Git version >= 2.9.5 ? ... yes (2.18.1) Git user has default SSH configuration? ... yes Active users: ... 13 Elasticsearch version 5.1 - 5.5? ... skipped (elasticsearch is disabled)
Checking GitLab ... Finished