Skip to content

Commit

Permalink
handle pkg-bindings errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Feb 26, 2014
1 parent 7d55d60 commit 6cfd5c2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package/yast2-registration.spec
Expand Up @@ -28,8 +28,8 @@ License: GPL-2.0

Requires: yast2 >= 2.23.13
Requires: yast2-pkg-bindings >= 2.17.20
# Y2Logger
Requires: yast2-ruby-bindings >= 3.1.7
# N_() method
Requires: yast2-ruby-bindings >= 3.1.12
# SCC API library
Requires: rubygem-scc_api >= 0.2.4
Requires: yast2-slp >= 3.1.2
Expand Down
34 changes: 28 additions & 6 deletions src/clients/inst_scc.rb
Expand Up @@ -28,6 +28,8 @@
require "tmpdir"
require "fileutils"

require "registration/exceptions"

module Yast
class InstSccClient < Client
include Yast::Logger
Expand Down Expand Up @@ -90,6 +92,9 @@ def main
else
Report.Error(_("Registration failed."))
end
rescue Registration::PkgError => e
log.error("Pkg error: #{e.message}")
Report.Error(_(e.message))
rescue Exception => e
log.error("SCC registration failed: #{e}, #{e.backtrace}")
Report.Error(_("Registration failed."))
Expand Down Expand Up @@ -144,8 +149,12 @@ def register(email, reg_code)
)

Progress.NextStage
add_services(product_services, credentials)
Progress.Finish

begin
add_services(product_services, credentials)
ensure
Progress.Finish
end
end
end

Expand All @@ -154,7 +163,10 @@ def add_services(product_services, credentials)
# save repositories before refreshing added services (otherwise
# pkg-bindings will treat them as removed by the service refresh and
# unload them)
Pkg.SourceSaveAll
if !Pkg.SourceSaveAll
# error message
raise Registration::PkgError, N_("Saving repository configuration failed.")
end

# each registered product
product_services.each do |product_service|
Expand All @@ -170,10 +182,20 @@ def add_services(product_services, credentials)
credentials.file = service.name + "_credentials"
credentials.write

Pkg.ServiceAdd(service.name, service.url.to_s)
if !Pkg.ServiceAdd(service.name, service.url.to_s)
# error message
raise Registration::PkgError, N_("Adding the service failed.")
end
# refresh works only for saved services
Pkg.ServiceSave(service.name)
Pkg.ServiceRefresh(service.name)
if !Pkg.ServiceSave(service.name)
# error message
raise Registration::PkgError, N_("Saving the new service failed.")
end

if !Pkg.ServiceRefresh(service.name)
# error message
raise Registration::PkgError, N_("The service refresh has failed.")
end

Progress.NextStep
end
Expand Down
27 changes: 27 additions & 0 deletions src/lib/registration/exceptions.rb
@@ -0,0 +1,27 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2014 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
#
#
module Registration
# Exception class for handling all Pkg errors
class PkgError < RuntimeError
end
end

0 comments on commit 6cfd5c2

Please sign in to comment.