diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index 10e81c1ac34420b56f0a8eda1e25fd645daf0b61..e703b9d79bb8e1bee4b528d2fb868a6e671fc8a7 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -121,6 +121,19 @@ def language end def transformed_blob_data - @transformed_blob ||= ( blob.path.ends_with?('.ipynb') && IpynbDiff.transform(blob.data, options: { include_metadata: false, cell_decorator: :percent }) ) || blob.data + @transformed_blob ||= if blob.path.ends_with?('.ipynb') + new_blob = IpynbDiff.transform(blob.data, + raise_errors: true, + options: { include_metadata: false, cell_decorator: :percent }) + + Gitlab::AppLogger.info(new_blob ? 'IPYNBDIFF_BLOB_GENERATED' : 'IPYNBDIFF_BLOB_NIL') + + new_blob + end + + @transformed_blob ||= blob.data + rescue IpynbDiff::InvalidNotebookError => e + Gitlab::ErrorTracking.track_exception(e, issue_url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/344676') + blob.data end end diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index cd08e9e2526d41d374d0137ef0e01edb0440de75..4cd5e9990270c096cd4cff1291d9a659743e46e6 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -458,9 +458,17 @@ def preprocess_before_diff(diff) new_diff = IpynbDiff.diff(from, to, diff_opts: { context: 5, include_diff_info: true }, - transform_options: { cell_decorator: :percent } ) + transform_options: { cell_decorator: :percent }, + raise_if_invalid_notebook: true) diff.diff = new_diff.scan(/.*\n/)[2..-1].join('') if new_diff + + Gitlab::AppLogger.info({ message: new_diff ? 'IPYNB_DIFF_GENERATED' : 'IPYNB_DIFF_NIL', + from: from&.to_s, to: to&.to_s, + lib_version: Gem.loaded_specs["ipynbdiff"].version.version }) + + rescue IpynbDiff::InvalidNotebookError => e + Gitlab::ErrorTracking.track_exception(e, issue_url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/344676') end def alternate_viewer_class