Class: Yast::InstErrorClass

Inherits:
Module
  • Object
show all
Defined in:
library/control/src/modules/InstError.rb

Instance Method Summary collapse

Instance Method Details

#mainObject


35
36
37
38
39
40
41
42
43
# File 'library/control/src/modules/InstError.rb', line 35

def main
  Yast.import "UI"
  textdomain "base"

  Yast.import "Icon"
  Yast.import "Label"
  Yast.import "String"
  Yast.import "Report"
end

#SaveLogsObject


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'library/control/src/modules/InstError.rb', line 45

def SaveLogs
  env_home = ENV["HOME"]

  homedir = if env_home && !env_home.empty?
    env_home
  else
    Builtins.y2warning("Home is not defined in env. Using '/'")
    "/"
  end
  homedir += "/y2logs.tgz"

  savelogsto = UI.AskForSaveFileName(
    homedir,
    "*.tgz *.tar.gz *.tar.bz2",
    _("Save y2logs to...")
  )

  return nil if savelogsto.nil?

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

  cmd = Convert.to_map(
    WFM.Execute(
      path(".local.bash_output"),
      Builtins.sformat("/usr/sbin/save_y2logs '%1'", String.Quote(savelogsto))
    )
  )
  dialog_ret = nil

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

    Report.Error(
      Builtins.sformat(
        # Error message, %1 is replaced with a filename
        # %2 with am error reason (there is a newline between %1 and %2)
        _("Unable to save YaST logs to %1\n%2"),
        savelogsto,
        Ops.get_string(cmd, "stderr", "")
      )
    )

    dialog_ret = false
  else
    Builtins.y2milestone("Logs have been saved to: %1", savelogsto)
    dialog_ret = true
  end

  UI.CloseDialog

  dialog_ret
end

#ShowErrorPopUp(heading, error_text, details) ⇒ Object

Function opens a pop-up error message (defined by the parameters). Reports where to report a bug and which logs to attach. It additionally offers to save logs directly from the dialog.

Parameters:

  • heading (String)
  • error_text (String)
  • details (String)

    (displayed as a plain text, can contain multiple lines)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'library/control/src/modules/InstError.rb', line 109

def ShowErrorPopUp(heading, error_text, details)
  success = UI.OpenDialog(
    Opt(:decorated, :warncolor),
    VBox(
      Left(HBox(HSquash(MarginBox(0.5, 0.2, Icon.Error)), Heading(heading))),
      MarginBox(
        1,
        0.5,
        VBox(
          Left(Label(error_text)),
          # `VSpacing (1),
          Left(
            if details.nil?
              Label(
                Builtins.sformat(
                  # TRANSLATORS: part of an error message
                  # // %1 - logfile, possibly with errors
                  _(
                    "More information can be found near the end of the '%1' file."
                  ),
                  "/var/log/YaST2/y2log"
                )
              )
            else
              MinSize(80, 10, RichText(Opt(:plainText, :hstretch), details))
            end
          ),
          # `VSpacing (1),
          Left(
            Label(
              Builtins.sformat(
                # TRANSLATORS: part of an error message
                # %1 - link to our bugzilla
                # %2 - directory where YaST logs are stored
                # %3 - link to the Yast Bug Reporting HOWTO Web page
                _(
                  "This is worth reporting a bug at %1.\n" \
                    "Please, attach also all YaST logs stored in the '%2' directory.\n" \
                    "See %3 for more information about YaST logs."
                ),
                "http://bugzilla.suse.com/",
                "/var/log/YaST2/",
                # link to the Yast Bug Reporting HOWTO
                # for translators: use the localized page for your language if it exists,
                # check the combo box "In other laguages" on top of the page
                _("http://en.opensuse.org/Bugs/YaST")
              )
            )
          )
        )
      ),
      ButtonBox(
        # FIXME: BNC #422612, Use `opt(`noSanityCheck) later
        PushButton(
          Id(:save_y2logs),
          Opt(:cancelButton),
          _("&Save YaST Logs...")
        ),
        PushButton(Id(:ok), Opt(:key_F10), Label.OKButton)
      )
    )
  )

  if success != true
    Builtins.y2error(
      "Cannot open a dialog: %1/%2/%3",
      heading,
      error_text,
      details
    )
    return
  end

  loop do
    uret = UI.UserInput

    break if uret != :save_y2logs

    SaveLogs()
  end

  UI.CloseDialog

  nil
end

#ShowErrorPopupWithLogs(error_text) ⇒ Object

Function is similar to ShowErrorPopUp but the error details are grabbed automatically from YaST logs.

Parameters:

  • error_text (String)

    (e.g., "Client inst_abc returned invalid data.")


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'library/control/src/modules/InstError.rb', line 199

def ShowErrorPopupWithLogs(error_text)
  cmd = Convert.to_map(
    WFM.Execute(
      path(".local.bash_output"),
      "/usr/bin/tail -n 200 /var/log/YaST2/y2log | /usr/bin/grep ' <\\(3\\|5\\)> '"
    )
  )

  details = cmd["stdout"] if cmd["exit"] == 0 && !cmd["stdout"].empty?
  ShowErrorPopUp(
    _("Installation Error"),
    error_text,
    details
  )

  nil
end