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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
1a7d9346
Commit
1a7d9346
authored
Mar 30, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix wrong error handling in update page service
parent
0ce07326
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
9 deletions
+42
-9
app/services/projects/update_pages_service.rb
app/services/projects/update_pages_service.rb
+9
-7
spec/services/projects/update_pages_service_spec.rb
spec/services/projects/update_pages_service_spec.rb
+33
-2
No files found.
app/services/projects/update_pages_service.rb
View file @
1a7d9346
...
...
@@ -37,9 +37,10 @@ module Projects
deploy_page!
(
archive_public_path
)
success
end
rescue
InvaildStateError
,
FailedToExtractError
=>
e
register_failure
rescue
InvaildStateError
=>
e
error
(
e
.
message
)
rescue
=>
e
error
(
e
.
message
,
false
)
end
private
...
...
@@ -50,12 +51,13 @@ module Projects
super
end
def
error
(
message
,
http_status
=
nil
)
def
error
(
message
,
delete_artifact
=
true
)
register_failure
log_error
(
"Projects::UpdatePagesService:
#{
message
}
"
)
@status
.
allow_failure
=
!
latest?
@status
.
description
=
message
@status
.
drop
(
:script_failure
)
delete_artifact!
delete_artifact!
if
delete_artifact
super
end
...
...
@@ -76,7 +78,7 @@ module Projects
elsif
artifacts
.
ends_with?
(
'.zip'
)
extract_zip_archive!
(
temp_path
)
else
raise
FailedToExtract
Error
,
'unsupported artifacts format'
raise
InvaildState
Error
,
'unsupported artifacts format'
end
end
...
...
@@ -91,13 +93,13 @@ module Projects
end
def
extract_zip_archive!
(
temp_path
)
raise
FailedToExtract
Error
,
'missing artifacts metadata'
unless
build
.
artifacts_metadata?
raise
InvaildState
Error
,
'missing artifacts metadata'
unless
build
.
artifacts_metadata?
# Calculate page size after extract
public_entry
=
build
.
artifacts_metadata_entry
(
SITE_PATH
,
recursive:
true
)
if
public_entry
.
total_size
>
max_size
raise
FailedToExtract
Error
,
"artifacts for pages are too large:
#{
public_entry
.
total_size
}
"
raise
InvaildState
Error
,
"artifacts for pages are too large:
#{
public_entry
.
total_size
}
"
end
# Requires UnZip at least 6.00 Info-ZIP.
...
...
spec/services/projects/update_pages_service_spec.rb
View file @
1a7d9346
...
...
@@ -169,10 +169,41 @@ describe Projects::UpdatePagesService do
end
it
'raises an error'
do
ex
pect
{
execute
}.
to
raise_error
(
SocketError
)
ex
ecute
build
.
reload
expect
(
build
.
artifacts?
).
to
eq
(
true
)
expect
(
deploy_status
).
to
be_failed
expect
(
build
.
artifacts?
).
to
be_truthy
end
end
context
'when failed to extract zip artifacts'
do
before
do
allow_any_instance_of
(
described_class
)
.
to
receive
(
:extract_zip_archive!
)
.
and_raise
(
Projects
::
UpdatePagesService
::
FailedToExtractError
)
end
it
'raises an error'
do
execute
build
.
reload
expect
(
deploy_status
).
to
be_failed
expect
(
build
.
artifacts?
).
to
be_truthy
end
end
context
'when missing artifacts metadata'
do
before
do
allow
(
build
).
to
receive
(
:artifacts_metadata?
).
and_return
(
false
)
end
it
'raises an error'
do
execute
build
.
reload
expect
(
deploy_status
).
to
be_failed
expect
(
build
.
artifacts?
).
to
be_falsey
end
end
end
...
...
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