fixed bug #224216 (uncaught checksum exception) (minimal fix for 10.2 YOU, more work...
authorJan Kupec <jkupec@suse.cz>
Mon, 18 Dec 2006 12:17:00 +0000 (12:17 +0000)
committerJan Kupec <jkupec@suse.cz>
Mon, 18 Dec 2006 12:17:00 +0000 (12:17 +0000)
src/zmart-misc.cc
src/zmart-source-callbacks.h
src/zypper.cc

index 7362255..6aafb83 100644 (file)
@@ -711,10 +711,33 @@ int solve_and_commit (bool non_interactive) {
       if (!confirm_licenses(non_interactive)) return ZYPPER_EXIT_OK;
 
       cerr_v << "committing" << endl;
-      ZYppCommitResult result = God->commit( ZYppCommitPolicy() );
-      if (!result._errors.empty())
-        retv = ZYPPER_EXIT_ERR_ZYPP;
-      cerr_v << result << std::endl;
+      
+      try {
+        ZYppCommitResult result = God->commit( ZYppCommitPolicy() );
+
+        if (!result._errors.empty())
+          retv = ZYPPER_EXIT_ERR_ZYPP;
+
+        cerr_v << result << std::endl;
+      }
+      catch ( const Exception & excpt_r ) {
+        ZYPP_CAUGHT( excpt_r );
+        
+        // special handling for failed integrity exception
+        if (excpt_r.msg().find("fails integrity check") != string::npos) {
+          cerr << endl
+            << _("Package integrity check failed. This may be a problem"
+            " with installation source or media. Try one of the following:\n"
+            "\n"
+            "- just retry previous command\n"
+            "- refresh installation sources using 'zypper refresh'\n"
+            "- use another installation media (if e.g. damaged)\n"
+            "- use another installation source") << endl;
+          return ZYPPER_EXIT_ERR_ZYPP;
+        }
+        else
+          ZYPP_RETHROW( excpt_r );
+      }
     }
   }
 
index e24c6c1..538fd94 100644 (file)
@@ -192,6 +192,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   
   virtual Action problem( zypp::Resolvable::constPtr resolvable_ptr, Error /*error*/, cbstring description )
   {
+    // TODO read user's answer whether to retry or what. Consider non-interactive mode, too
     std::cerr << resolvable_ptr << " " << description << std::endl;
     std::cerr << "(aborting)" << std::endl;
     return ABORT;
index ca98928..09807b9 100644 (file)
@@ -893,6 +893,32 @@ int one_command(const string& command, int argc, char **argv)
   return ZYPPER_EXIT_ERR_BUG;
 }
 
+/// tell to report a bug, and how
+// (multiline, with endls)
+ostream& report_a_bug (ostream& stm) {
+  return stm << _("Please report a bug about this.") << endl
+    // remember not to translate the URL
+    // unless you translate the actual page :)
+            << _("See http://en.opensuse.org/Zypper#Troubleshooting for instructions.") << endl;
+}
+
+/// process one command from the OS shell or the zypper shell
+// catch unexpected exceptions and tell the user to report a bug (#224216)
+int safe_one_command(const string& command, int argc, char **argv)
+{
+  int ret = ZYPPER_EXIT_ERR_BUG;
+  try {
+    ret = one_command (command, argc, argv);
+  }
+  catch (const Exception & ex) {
+    ZYPP_CAUGHT(ex);
+    cerr << _("Unexpected exception.") << endl;
+    cerr << ex.asUserString() << endl;
+    report_a_bug(cerr);
+  }
+  return ret;
+}
+
 void command_shell ()
 {
   bool loop = true;
@@ -914,7 +940,7 @@ void command_shell ()
     if (command == "exit")
       loop = false;
     else
-      one_command (command, sh_argc, sh_argv);
+      safe_one_command (command, sh_argc, sh_argv);
   }
 }
 
@@ -938,7 +964,7 @@ int main(int argc, char **argv)
   if (command == "shell" || command == "sh")
     command_shell ();
   else
-    ret = one_command (command, argc, argv);
+    ret = safe_one_command (command, argc, argv);
 
   return ret;
 }