Skip to content
代码片段 群组 项目
未验证 提交 c9f59e52 编辑于 作者: Eduardo Bonet's avatar Eduardo Bonet 提交者: GitLab
浏览文件

Merge branch...

Merge branch '466069-ai-classes-shouldn-t-rescue-standard-error-without-tracking-the-error' into 'master' 

AI classes should log and track when StandardError is rescued

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/155600



Merged-by: default avatarEduardo Bonet <ebonet@gitlab.com>
Approved-by: default avatarEduardo Bonet <ebonet@gitlab.com>
Co-authored-by: default avatarAllison Browne <abrowne@gitlab.com>
No related branches found
No related tags found
无相关合并请求
显示 24 个添加5 个删除
......@@ -31,6 +31,7 @@ def test_completion
nil
rescue StandardError => err
Gitlab::ErrorTracking.track_exception(err)
err.message
end
......
......@@ -54,7 +54,9 @@ class Executor < Tool
def perform(&_block)
Answer.new(status: :ok, context: context, content: request, tool: nil)
rescue StandardError
rescue StandardError => e
Gitlab::ErrorTracking.track_exception(e)
Answer.error_answer(context: context, content: _("Unexpected error"))
end
traceable :perform, run_type: 'tool'
......
......@@ -44,7 +44,7 @@ def perform(&_block)
options[:suggestions] += error_message
rescue StandardError => e
logger.error(message: "Error", error: e.message, class: self.class.to_s)
Gitlab::ErrorTracking.track_exception(e)
return Answer.error_answer(context: context, content: _("Unexpected error"))
end
......
......@@ -11,7 +11,9 @@ def perform
content = request(&streamed_request_handler(StreamedAnswer.new))
Answer.new(status: :ok, context: context, content: content, tool: nil)
rescue StandardError
rescue StandardError => e
Gitlab::ErrorTracking.track_exception(e)
Answer.error_answer(context: context, content: _("Unexpected error"))
end
traceable :perform, run_type: 'tool'
......
......@@ -53,6 +53,12 @@
stub_request(:post, /#{Gitlab::AiGateway.url}/).to_raise(StandardError.new('an error'))
end
it 'tracks an exception' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(instance_of(StandardError))
result
end
it_behaves_like 'error response', 'an error'
end
end
......
......@@ -56,6 +56,7 @@
it 'returns error answer' do
allow(tool).to receive(:request).and_raise(StandardError)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(instance_of(StandardError))
expect(tool.execute.content).to eq('Unexpected error')
end
end
......
......@@ -103,6 +103,8 @@
it 'returns error answer' do
allow(tool).to receive(:request).and_raise(StandardError)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(instance_of(StandardError))
expect(tool.execute.content).to eq('Unexpected error')
end
end
......
......@@ -110,6 +110,8 @@
it 'returns error answer' do
allow(tool).to receive(:request).and_raise(StandardError)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(instance_of(StandardError))
expect(tool.execute.content).to eq('Unexpected error')
end
end
......
......@@ -94,6 +94,8 @@
it 'returns error answer' do
allow(tool).to receive(:request).and_raise(StandardError)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(instance_of(StandardError))
expect(tool.execute.content).to eq('Unexpected error')
end
end
......
......@@ -82,7 +82,8 @@ def track_and_raise_for_dev_exception(exception, extra = {}, tags = {})
raise exception if should_raise_for_dev?
end
# This should be used when you only want to track the exception.
# This should be used when you want to track the exception and not raise
# with the default trackers (Sentry and Logger).
#
# If the exception implements the method `sentry_extra_data` and that method
# returns a Hash, then the return value of that method will be merged into
......@@ -93,7 +94,7 @@ def track_exception(exception, extra = {}, tags = {})
end
# This should be used when you only want to log the exception,
# but not send it to Sentry.
# but not send it to Sentry or raise.
#
# If the exception implements the method `sentry_extra_data` and that method
# returns a Hash, then the return value of that method will be merged into
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册