diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-25 15:07:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-25 15:07:36 +0000 |
commit | cdd95ddd0197b8709947c2b3b4e0333e1d9a2934 (patch) | |
tree | 31c54297728d8ddee38203e12f91a0594fa6e223 | |
parent | d45691788ec45d0da3508c438ffdf43b08781f04 (diff) | |
download | gitlab-ce-cdd95ddd0197b8709947c2b3b4e0333e1d9a2934.tar.gz |
Add latest changes from gitlab-org/gitlab@master
4 files changed, 32 insertions, 1 deletions
diff --git a/changelogs/unreleased/121714-fix-sentry-stack-trace-highlight-for-php.yml b/changelogs/unreleased/121714-fix-sentry-stack-trace-highlight-for-php.yml new file mode 100644 index 00000000000..4f3b80dfcaa --- /dev/null +++ b/changelogs/unreleased/121714-fix-sentry-stack-trace-highlight-for-php.yml @@ -0,0 +1,5 @@ +--- +title: Fix stack trace highlight for PHP +merge_request: 22258 +author: +type: fixed diff --git a/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb b/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb index a403275fd4e..1e490e52c43 100644 --- a/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb +++ b/lib/gitlab/error_tracking/stack_trace_highlight_decorator.rb @@ -28,7 +28,7 @@ module Gitlab end def highlight_entry_context(filename, context) - language = Rouge::Lexer.guess_by_filename(filename).tag + language = guess_language_by_filename(filename) context.map do |line_number, line_of_code| [ @@ -38,6 +38,12 @@ module Gitlab ] end end + + def guess_language_by_filename(filename) + Rouge::Lexer.guess_by_filename(filename).tag + rescue Rouge::Guesser::Ambiguous => e + e.alternatives.min_by(&:tag)&.tag + end end end end diff --git a/spec/factories/error_tracking/error_event.rb b/spec/factories/error_tracking/error_event.rb index c4dcd67bc9f..1590095f1bd 100644 --- a/spec/factories/error_tracking/error_event.rb +++ b/spec/factories/error_tracking/error_event.rb @@ -36,6 +36,16 @@ FactoryBot.define do ] }, { + 'function' => 'print', + 'lineNo' => 3, + 'filename' => 'hello_world.php', + 'context' => [ + [1, "// PHP/Hack example\n"], + [2, "<?php\n"], + [3, "echo 'Hello, World!';\n"] + ] + }, + { 'filename' => 'blank.txt' } ] diff --git a/spec/lib/gitlab/error_tracking/stack_trace_highlight_decorator_spec.rb b/spec/lib/gitlab/error_tracking/stack_trace_highlight_decorator_spec.rb index 04ef5ba516e..d553fb4848b 100644 --- a/spec/lib/gitlab/error_tracking/stack_trace_highlight_decorator_spec.rb +++ b/spec/lib/gitlab/error_tracking/stack_trace_highlight_decorator_spec.rb @@ -49,6 +49,16 @@ describe Gitlab::ErrorTracking::StackTraceHighlightDecorator do ] }, { + 'function' => 'print', + 'lineNo' => 3, + 'filename' => 'hello_world.php', + 'context' => [ + [1, '<span id="LC1" class="line" lang="hack"><span class="c1">// PHP/Hack example</span></span>'], + [2, '<span id="LC1" class="line" lang="hack"><span class="cp"><?php</span></span>'], + [3, '<span id="LC1" class="line" lang="hack"><span class="k">echo</span> <span class="s1">\'Hello, World!\'</span><span class="p">;</span></span>'] + ] + }, + { 'filename' => 'blank.txt' } ] |