Skip to content

"Encoding::CompatibilityError" is shown when using a commit message validation with specific regular expression

Summary

"Encoding::CompatibilityError" is shown when using a commit message validation with specific regular expression when editing file via Open single file editor.

Steps to reproduce

  • Create a new project.
  • Go to Settings > Repository > Push rules > Require expression in commit messages and configure the following regular expression: ^(¯\\_\(ツ\)_\/¯).
  • Try to make a new commit via Edit single file and specify commit message not matching the expression (anything besides ¯\_(ツ)_/¯).

Example Project

Public project: https://gitlab.com/atanayno/regexp-test

What is the current bug behavior?

The commit fails with error 500 in UI: 500 Encoding Error Page can't be loaded because of an encoding error.

error_500

What is the expected correct behavior?

The valid error message should be shown via Edit single file UI (same as for Web IDE):

13:update reference: running pre-receive hooks: GitLab: Commit message does not follow the pattern '^(¯\\_\(ツ\)_\/¯)'.

Relevant logs and/or screenshots

Error message from the production.log:

Encoding::CompatibilityError (incompatible character encodings: ASCII-8BIT and UTF-8):
  app/views/layouts/_page.html.haml:50
  app/views/layouts/application.html.haml:22
  app/views/layouts/project.html.haml:31
  app/controllers/application_controller.rb:144:in `render'
  ee/lib/gitlab/ip_address_state.rb:10:in `with'
  ee/app/controllers/ee/application_controller.rb:45:in `set_current_ip_address'
  app/controllers/application_controller.rb:500:in `set_current_admin'
  lib/gitlab/session.rb:11:in `with_session'
  app/controllers/application_controller.rb:491:in `set_session_storage'
  lib/gitlab/i18n.rb:107:in `with_locale'
  lib/gitlab/i18n.rb:113:in `with_user_locale'
  app/controllers/application_controller.rb:482:in `set_locale'
  app/controllers/application_controller.rb:475:in `set_current_context'
  lib/gitlab/metrics/elasticsearch_rack_middleware.rb:16:in `call'
  lib/gitlab/middleware/memory_report.rb:13:in `call'
  lib/gitlab/middleware/speedscope.rb:13:in `call'
  lib/gitlab/database/load_balancing/rack_middleware.rb:23:in `call'
  lib/gitlab/middleware/rails_queue_duration.rb:33:in `call'
  lib/gitlab/metrics/rack_middleware.rb:16:in `block in call'
  lib/gitlab/metrics/web_transaction.rb:46:in `run'
  lib/gitlab/metrics/rack_middleware.rb:16:in `call'
  lib/gitlab/jira/middleware.rb:19:in `call'
  lib/gitlab/middleware/go.rb:20:in `call'
  lib/gitlab/etag_caching/middleware.rb:21:in `call'
  lib/gitlab/middleware/query_analyzer.rb:11:in `block in call'
  lib/gitlab/database/query_analyzer.rb:37:in `within'
  lib/gitlab/middleware/query_analyzer.rb:11:in `call'
  lib/gitlab/middleware/multipart.rb:173:in `call'
  lib/gitlab/middleware/read_only/controller.rb:50:in `call'
  lib/gitlab/middleware/read_only.rb:18:in `call'
  lib/gitlab/middleware/same_site_cookies.rb:27:in `call'
  lib/gitlab/middleware/basic_health_check.rb:25:in `call'
  lib/gitlab/middleware/handle_malformed_strings.rb:21:in `call'
  lib/gitlab/middleware/handle_ip_spoof_attack_error.rb:25:in `call'
  lib/gitlab/middleware/request_context.rb:15:in `call'
  lib/gitlab/middleware/webhook_recursion_detection.rb:15:in `call'
  config/initializers/fix_local_cache_middleware.rb:11:in `call'
  lib/gitlab/middleware/compressed_json.rb:44:in `call'

In production_json.log we do not see details of the error. It looks like that:

{
  "method": "PUT",
  "path": "/root/regular-expression-commit-test/-/update/main/README.md",
  "format": "html",
  "controller": "Projects::BlobController",
  "action": "update",
  "status": 500,
  "time": "2023-08-10T11:42:37.873Z",
  "params": [
    {
      "key": "_method",
      "value": "put"
    },
    {
      "key": "authenticity_token",
      "value": "[FILTERED]"
    },
    {
      "key": "file_path",
      "value": "README.md"
    },
    {
      "key": "commit_message",
      "value": "Update README.mdaaa"
    },
    {
      "key": "branch_name",
      "value": "main"
    },
    {
      "key": "original_branch",
      "value": "main"
    },
    {
      "key": "last_commit_sha",
      "value": "335cd0de96b8064b3e5d4bac7f0bf96b85475160"
    },
    {
      "key": "content",
      "value": "[FILTERED]"
    },
    {
      "key": "from_merge_request_iid",
      "value": ""
    },
    {
      "key": "namespace_id",
      "value": "root"
    },
    {
      "key": "project_id",
      "value": "regular-expression-commit-test"
    },
    {
      "key": "id",
      "value": "main/README.md"
    }
  ],
  "correlation_id": "01H7FM2Y7VRY98T09EY5HENY2S",
  "meta.caller_id": "Projects::BlobController#update",
  "meta.remote_ip": "80.113.68.61",
  "meta.feature_category": "source_code_management",
  "meta.user": "root",
  "meta.user_id": 1,
  "meta.project": "root/regular-expression-commit-test",
...
}

Although, valid error message is shown in gitaly/current log:

{
  "branch_name": "bWFpbg==",
  "command.count": 12,
  "command.cpu_time_ms": 11,
  "command.inblock": 0,
  "command.majflt": 0,
  "command.maxrss": 341200,
  "command.minflt": 2057,
  "command.oublock": 24,
  "command.real_time_ms": 21,
  "command.spawn_token_fork_ms": 0,
  "command.spawn_token_wait_ms": 0,
  "command.system_time_ms": 2,
  "command.user_time_ms": 9,
  "correlation_id": "01H7FM2Y7VRY98T09EY5HENY2S",
  "error": "update reference: running pre-receive hooks: GitLab: Commit message does not follow the pattern '^(¯\\\\_\\(ツ\\)_\\/¯)'",
  "force": false,
  "grpc.code": "Internal",
  "grpc.meta.auth_version": "v2",
  "grpc.meta.client_name": "gitlab-web",
  "grpc.meta.deadline_type": "regular",
  "grpc.meta.method_type": "client_stream",
  "grpc.method": "UserCommitFiles",
  "grpc.request.deadline": "2023-08-10T11:43:32.433",
  "grpc.request.fullMethod": "/gitaly.OperationService/UserCommitFiles",
  "grpc.request.payload_bytes": 6857,
  "grpc.response.payload_bytes": 0,
  "grpc.service": "gitaly.OperationService",
  "grpc.start_time": "2023-08-10T11:42:37.433",
  "grpc.time_ms": 157.185,
  "level": "error",
  "msg": "finished streaming call with code Internal",
  ...
}

Output of checks

  • This bug happens on GitLab.com.
  • Reproduced the issue with a self-managed instance of GitLab 16.2.1. Above-mentioned logs are from this instance.
Edited by Alexandr Tanayno