Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
53477a58
Commit
53477a58
authored
Mar 23, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add logging to snippet services
parent
81835524
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
6 deletions
+24
-6
app/services/snippets/create_service.rb
app/services/snippets/create_service.rb
+1
-0
app/services/snippets/update_service.rb
app/services/snippets/update_service.rb
+2
-1
spec/services/snippets/create_service_spec.rb
spec/services/snippets/create_service_spec.rb
+6
-0
spec/services/snippets/update_service_spec.rb
spec/services/snippets/update_service_spec.rb
+15
-5
No files found.
app/services/snippets/create_service.rb
View file @
53477a58
...
...
@@ -50,6 +50,7 @@ module Snippets
snippet_saved
rescue
=>
e
# Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ...
snippet
.
errors
.
add
(
:base
,
e
.
message
)
log_error
(
e
.
message
)
# If the commit action failed we need to remove the repository if exists
snippet
.
repository
.
remove
if
snippet
.
repository_exists?
...
...
app/services/snippets/update_service.rb
View file @
53477a58
...
...
@@ -51,8 +51,9 @@ module Snippets
# the changes
create_commit
(
snippet
)
if
snippet
.
repository_exists?
end
rescue
rescue
=>
e
snippet
.
errors
.
add
(
:repository
,
'Error updating the snippet'
)
log_error
(
e
.
message
)
false
end
...
...
spec/services/snippets/create_service_spec.rb
View file @
53477a58
...
...
@@ -199,6 +199,12 @@ describe Snippets::CreateService do
expect
(
SnippetRepository
.
count
).
to
be_zero
end
it
'logs the error'
do
expect
(
Gitlab
::
AppLogger
).
to
receive
(
:error
).
with
(
'foobar'
)
subject
end
it
'returns the error'
do
response
=
subject
...
...
spec/services/snippets/update_service_spec.rb
View file @
53477a58
...
...
@@ -167,13 +167,23 @@ describe Snippets::UpdateService do
expect
(
blob
.
data
).
to
eq
(
options
[
:content
])
end
it
'returns error when the commit action fails'
do
allow
(
snippet
.
snippet_repository
).
to
receive
(
:multi_files_action
).
and_raise
(
SnippetRepository
::
CommitError
)
context
'when an error is raised'
do
before
do
allow
(
snippet
.
snippet_repository
).
to
receive
(
:multi_files_action
).
and_raise
(
SnippetRepository
::
CommitError
,
'foobar'
)
end
response
=
subject
it
'logs the error'
do
expect
(
Gitlab
::
AppLogger
).
to
receive
(
:error
).
with
(
'foobar'
)
expect
(
response
).
to
be_error
expect
(
response
.
payload
[
:snippet
].
errors
.
full_messages
).
to
eq
[
'Repository Error updating the snippet'
]
subject
end
it
'returns error with generic error message'
do
response
=
subject
expect
(
response
).
to
be_error
expect
(
response
.
payload
[
:snippet
].
errors
.
full_messages
).
to
eq
[
'Repository Error updating the snippet'
]
end
end
it
'returns error if snippet does not have a snippet_repository'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment