• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-yast2 / 8248418554

12 Mar 2024 12:02PM UTC coverage: 40.575% (+0.02%) from 40.555%
8248418554

push

github

web-flow
Merge pull request #1307 from yast/slehpc_sp3

13 of 14 new or added lines in 1 file covered. (92.86%)

2 existing lines in 1 file now uncovered.

12003 of 29582 relevant lines covered (40.58%)

6.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/library/control/src/modules/InstError.rb
1
# ***************************************************************************
2
#
3
# Copyright (c) 2002 - 2012 Novell, Inc.
4
# All Rights Reserved.
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of version 2 of the GNU General Public License as
8
# published by the Free Software Foundation.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, contact Novell, Inc.
17
#
18
# To contact Novell about this file by physical or electronic mail,
19
# you may find current contact information at www.novell.com
20
#
21
# ***************************************************************************
22
# File:  modules/InstError.ycp
23
# Package:  Installation
24
# Summary:  Module for reporting installation errors
25
# Authors:  Lukas Ocilka <locilka@suse.cz>
26
#
27
# $Id$
28
#
29
# This module provides unified interface for reporting
30
# installation errors.
31
require "yast"
×
32

33
module Yast
×
34
  class InstErrorClass < Module
×
35
    def main
×
36
      Yast.import "UI"
×
37
      textdomain "base"
×
38

39
      Yast.import "Icon"
×
40
      Yast.import "Label"
×
41
      Yast.import "String"
×
42
      Yast.import "Report"
×
43
      Yast.import "OSRelease"
×
44
    end
×
45

46
    def SaveLogs
×
47
      env_home = ENV["HOME"]
×
48

49
      homedir = if env_home && !env_home.empty?
×
50
        env_home
×
51
      else
×
52
        Builtins.y2warning("Home is not defined in env. Using '/'")
×
53
        "/"
×
54
      end
×
55
      homedir += "/y2logs.tgz"
×
56

57
      savelogsto = UI.AskForSaveFileName(
×
58
        homedir,
×
59
        "*.tgz *.tar.gz *.tar.bz2",
×
60
        _("Save y2logs to...")
×
61
      )
×
62

63
      return nil if savelogsto.nil?
×
64

65
      # Busy message, %1 is replaced with a filename
66
      UI.OpenDialog(
×
67
        Label(Builtins.sformat(_("Saving YaST logs to %1..."), savelogsto))
×
68
      )
×
69
      Builtins.y2milestone("Saving YaST logs to: %1", savelogsto)
×
70

71
      cmd = Convert.to_map(
×
72
        WFM.Execute(
×
73
          path(".local.bash_output"),
×
74
          Builtins.sformat("/usr/sbin/save_y2logs '%1'", String.Quote(savelogsto))
×
75
        )
×
76
      )
×
77
      dialog_ret = nil
×
78

79
      if Ops.get_integer(cmd, "exit", -1) != 0
×
80
        Builtins.y2error("Unable to save logs to %1", savelogsto)
×
81

82
        Report.Error(
×
83
          Builtins.sformat(
×
84
            # Error message, %1 is replaced with a filename
85
            # %2 with am error reason (there is a newline between %1 and %2)
86
            _("Unable to save YaST logs to %1\n%2"),
×
87
            savelogsto,
×
88
            Ops.get_string(cmd, "stderr", "")
×
89
          )
×
90
        )
×
91

92
        dialog_ret = false
×
93
      else
×
94
        Builtins.y2milestone("Logs have been saved to: %1", savelogsto)
×
95
        dialog_ret = true
×
96
      end
×
97

98
      UI.CloseDialog
×
99

100
      dialog_ret
×
101
    end
×
102

103
    # Function opens a pop-up error message (defined by the parameters).
104
    # Reports where to report a bug and which logs to attach.
105
    # It additionally offers to save logs directly from the dialog.
106
    #
107
    # @param [String] heading
108
    # @param [String] error_text
109
    # @param [String] details (displayed as a plain text, can contain multiple lines)
110
    def ShowErrorPopUp(heading, error_text, details)
×
111
      bugzilla_url = "http://bugzilla.suse.com/"
×
112
      bugzilla_url = "http://bugzilla.opensuse.org" if OSRelease.ReleaseName.include? "openSUSE"
×
113
      success = UI.OpenDialog(
×
114
        Opt(:decorated, :warncolor),
×
115
        VBox(
×
116
          Left(HBox(HSquash(MarginBox(0.5, 0.2, Icon.Error)), Heading(heading))),
×
117
          MarginBox(
×
118
            1,
×
119
            0.5,
×
120
            VBox(
×
121
              Left(Label(error_text)),
×
122
              # `VSpacing (1),
123
              Left(
×
124
                if details.nil?
×
125
                  Label(
×
126
                    Builtins.sformat(
×
127
                      # TRANSLATORS: part of an error message
128
                      # // %1 - logfile, possibly with errors
129
                      _(
×
130
                        "More information can be found near the end of the '%1' file."
×
131
                      ),
×
132
                      "/var/log/YaST2/y2log"
×
133
                    )
×
134
                  )
×
135
                else
×
136
                  MinSize(80, 10, RichText(Opt(:plainText, :hstretch), details))
×
137
                end
×
138
              ),
×
139
              # `VSpacing (1),
140
              Left(
×
141
                Label(
×
142
                  Builtins.sformat(
×
143
                    # TRANSLATORS: part of an error message
144
                    # %1 - link to our bugzilla
145
                    # %2 - directory where YaST logs are stored
146
                    # %3 - link to the Yast Bug Reporting HOWTO Web page
147
                    _(
×
148
                      "This is worth reporting a bug at %1.\n" \
×
149
                        "Please, attach also all YaST logs stored in the '%2' directory.\n" \
×
150
                        "See %3 for more information about YaST logs."
×
151
                    ),
×
152
                    bugzilla_url,
×
153
                    "/var/log/YaST2/",
×
154
                    # link to the Yast Bug Reporting HOWTO
155
                    # for translators: use the localized page for your language if it exists,
156
                    # check the combo box "In other laguages" on top of the page
157
                    _("http://en.opensuse.org/Bugs/YaST")
×
158
                  )
×
159
                )
×
160
              )
×
161
            )
×
162
          ),
×
163
          ButtonBox(
×
164
            # FIXME: BNC #422612, Use `opt(`noSanityCheck) later
165
            PushButton(
×
166
              Id(:save_y2logs),
×
167
              Opt(:cancelButton),
×
168
              _("&Save YaST Logs...")
×
169
            ),
×
170
            PushButton(Id(:ok), Opt(:key_F10), Label.OKButton)
×
171
          )
×
172
        )
×
173
      )
×
174

175
      if success != true
×
176
        Builtins.y2error(
×
177
          "Cannot open a dialog: %1/%2/%3",
×
178
          heading,
×
179
          error_text,
×
180
          details
×
181
        )
×
182
        return
×
183
      end
×
184

185
      loop do
×
186
        uret = UI.UserInput
×
187

188
        break if uret != :save_y2logs
×
189

190
        SaveLogs()
×
191
      end
×
192

193
      UI.CloseDialog
×
194

195
      nil
×
196
    end
×
197

198
    # Function is similar to ShowErrorPopUp but the error details are grabbed automatically
199
    # from YaST logs.
200
    #
201
    # @param [String] error_text (e.g., "Client inst_abc returned invalid data.")
202
    def ShowErrorPopupWithLogs(error_text)
×
203
      cmd = Convert.to_map(
×
204
        WFM.Execute(
×
205
          path(".local.bash_output"),
×
206
          "/usr/bin/tail -n 200 /var/log/YaST2/y2log | /usr/bin/grep ' <\\(3\\|5\\)> '"
×
207
        )
×
208
      )
×
209

210
      details = cmd["stdout"] if cmd["exit"] == 0 && !cmd["stdout"].empty?
×
211
      ShowErrorPopUp(
×
212
        _("Installation Error"),
×
213
        error_text,
×
214
        details
×
215
      )
×
216

217
      nil
×
218
    end
×
219

220
    publish function: :ShowErrorPopUp, type: "void (string, string, string)"
×
221
    publish function: :ShowErrorPopupWithLogs, type: "void (string)"
×
222
  end
×
223

224
  InstError = InstErrorClass.new
×
225
  InstError.main
×
226
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc