Commit a660eaab authored by Eduardo Bonet's avatar Eduardo Bonet

Mitigating error IpynbDiff::InvalidTokenError

Sentry: https://sentry.gitlab.net/gitlab/gitlabcom/issues/3204685/

This error happens on the jsonparser that tokenizes the Notebook
file, but it happens very rarely and it's hard to reproduce. As a
mitigation, when users encounter this problem, we will fallback to
classic raw diffs.
parent 5a000354
...@@ -10,14 +10,12 @@ module Gitlab ...@@ -10,14 +10,12 @@ module Gitlab
transformed_for_diff(new_blob, old_blob) transformed_for_diff(new_blob, old_blob)
Gitlab::AppLogger.info({ message: 'IPYNB_DIFF_GENERATED' }) Gitlab::AppLogger.info({ message: 'IPYNB_DIFF_GENERATED' })
end end
rescue IpynbDiff::InvalidNotebookError => e rescue IpynbDiff::InvalidNotebookError, IpynbDiff::InvalidTokenError => e
Gitlab::ErrorTracking.log_exception(e) Gitlab::ErrorTracking.log_exception(e)
nil nil
end end
def transformed_diff(before, after) def transformed_diff(before, after)
Gitlab::AppLogger.info({ message: 'IPYNB_DIFF_GENERATED' })
transformed_diff = IpynbDiff.diff(before, after, transformed_diff = IpynbDiff.diff(before, after,
raise_if_invalid_nb: true, raise_if_invalid_nb: true,
diffy_opts: { include_diff_info: true }).to_s(:text) diffy_opts: { include_diff_info: true }).to_s(:text)
......
...@@ -57,7 +57,7 @@ module Gitlab ...@@ -57,7 +57,7 @@ module Gitlab
IpynbDiff.diff(source_diff.old_blob&.data, source_diff.new_blob&.data, IpynbDiff.diff(source_diff.old_blob&.data, source_diff.new_blob&.data,
raise_if_invalid_nb: true, raise_if_invalid_nb: true,
diffy_opts: { include_diff_info: true }) diffy_opts: { include_diff_info: true })
rescue IpynbDiff::InvalidNotebookError => e rescue IpynbDiff::InvalidNotebookError, IpynbDiff::InvalidTokenError => e
Gitlab::ErrorTracking.log_exception(e) Gitlab::ErrorTracking.log_exception(e)
nil nil
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment