diff options
author | Robert Speicher <robert@gitlab.com> | 2016-06-03 03:00:07 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-06-03 03:00:07 +0000 |
commit | 07b46517cc940b429515374e4e102ff04405e804 (patch) | |
tree | 4630b1e5602d095e34e434cd40999e43bd4728aa /app | |
parent | 74849f9783850676274a4e93a1b6335b5bb34f2e (diff) | |
parent | c9e8acd05846e981e26f940bd8c529839fcfc4a1 (diff) | |
download | gitlab-ce-07b46517cc940b429515374e4e102ff04405e804.tar.gz |
Merge branch 'fix/import-error-handling' into 'master'
Fix import error handling
Fixes https://gitlab.com/gitlab-com/support-forum/issues/745
This improves import error handling:
- Now if there's an error during importing before the job is scheduled, we also mark the project status as failed.
- Refactored setting the status to failed into one single method.
- Fixed some situations where the error message was missing or simply empty.
See merge request !4366
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project.rb | 12 | ||||
-rw-r--r-- | app/services/projects/create_service.rb | 26 | ||||
-rw-r--r-- | app/services/projects/import_service.rb | 2 | ||||
-rw-r--r-- | app/workers/repository_fork_worker.rb | 6 | ||||
-rw-r--r-- | app/workers/repository_import_worker.rb | 3 |
5 files changed, 36 insertions, 13 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 9ccf6a97df6..e4a9d17a20c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1017,4 +1017,16 @@ class Project < ActiveRecord::Base builds.running_or_pending.count(:all) end end + + def mark_import_as_failed(error_message) + original_errors = errors.dup + sanitized_message = Gitlab::UrlSanitizer.sanitize(error_message) + + import_fail + update_column(:import_error, sanitized_message) + rescue ActiveRecord::ActiveRecordError => e + Rails.logger.error("Error setting import status to failed: #{e.message}. Original error: #{sanitized_message}") + ensure + @errors = original_errors + end end diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 6728fabea1e..61cac5419ad 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -56,14 +56,14 @@ module Projects after_create_actions if @project.persisted? - @project.add_import_job if @project.import? - + if @project.errors.empty? + @project.add_import_job if @project.import? + else + fail(error: @project.errors.full_messages.join(', ')) + end @project rescue => e - message = "Unable to save project: #{e.message}" - Rails.logger.error(message) - @project.errors.add(:base, message) if @project - @project + fail(error: e.message) end protected @@ -103,5 +103,19 @@ module Projects end end end + + def fail(error:) + message = "Unable to save project. Error: #{error}" + message << "Project ID: #{@project.id}" if @project && @project.id + + Rails.logger.error(message) + + if @project && @project.import? + @project.errors.add(:base, message) + @project.mark_import_as_failed(message) + end + + @project + end end end diff --git a/app/services/projects/import_service.rb b/app/services/projects/import_service.rb index ef15ef6a473..c4838d31f2f 100644 --- a/app/services/projects/import_service.rb +++ b/app/services/projects/import_service.rb @@ -39,7 +39,7 @@ module Projects begin gitlab_shell.import_repository(project.path_with_namespace, project.import_url) rescue Gitlab::Shell::Error => e - raise Error, e.message + raise Error, "Error importing repository #{project.import_url} into #{project.path_with_namespace} - #{e.message}" end end diff --git a/app/workers/repository_fork_worker.rb b/app/workers/repository_fork_worker.rb index f9e32337983..d947f105516 100644 --- a/app/workers/repository_fork_worker.rb +++ b/app/workers/repository_fork_worker.rb @@ -15,8 +15,7 @@ class RepositoryForkWorker result = gitlab_shell.fork_repository(source_path, target_path) unless result logger.error("Unable to fork project #{project_id} for repository #{source_path} -> #{target_path}") - project.update(import_error: "The project could not be forked.") - project.import_fail + project.mark_import_as_failed('The project could not be forked.') return end @@ -24,8 +23,7 @@ class RepositoryForkWorker unless project.valid_repo? logger.error("Project #{project_id} had an invalid repository after fork") - project.update(import_error: "The forked repository is invalid.") - project.import_fail + project.mark_import_as_failed('The forked repository is invalid.') return end diff --git a/app/workers/repository_import_worker.rb b/app/workers/repository_import_worker.rb index fbc7ed63c6a..7d819fe78f8 100644 --- a/app/workers/repository_import_worker.rb +++ b/app/workers/repository_import_worker.rb @@ -13,8 +13,7 @@ class RepositoryImportWorker result = Projects::ImportService.new(project, current_user).execute if result[:status] == :error - project.update(import_error: Gitlab::UrlSanitizer.sanitize(result[:message])) - project.import_fail + project.mark_import_as_failed(result[:message]) return end |