Ver código fonte

implement correct error reporting

David Kalnischkies 15 anos atrás
pai
commit
ebfeeaedf5
4 arquivos alterados com 22 adições e 7 exclusões
  1. 12 2
      apt-pkg/edsp.cc
  2. 6 1
      apt-pkg/edsp.h
  3. 1 1
      cmdline/apt-dump-solver.cc
  4. 3 3
      cmdline/apt-internal-solver.cc

+ 12 - 2
apt-pkg/edsp.cc

@@ -256,6 +256,11 @@ bool EDSP::ReadResponse(int const input, pkgDepCache &Cache) {
 			else
 			else
 				std::clog << msg << std::endl;
 				std::clog << msg << std::endl;
 			continue;
 			continue;
+		} else if (section.Exists("Error") == true) {
+			std::cerr << "The solver encountered an error of type: " << section.FindS("Error") << std::endl;
+			std::cerr << "The following information might help you to understand what is wrong:" << std::endl;
+			std::cerr << SubstVar(SubstVar(section.FindS("Message"), "\n .\n", "\n\n"), "\n ", "\n") << std::endl << std::endl;
+			break;
 		} else if (section.Exists("Autoremove") == true)
 		} else if (section.Exists("Autoremove") == true)
 			type = "Autoremove";
 			type = "Autoremove";
 		else
 		else
@@ -457,8 +462,13 @@ bool EDSP::WriteProgress(unsigned short const percent, const char* const message
 	return true;
 	return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
-bool EDSP::WriteError(std::string const &message, FILE* output) { return false; }
-
+// EDSP::WriteError - format an error message to be send to file descriptor /*{{{*/
+bool EDSP::WriteError(char const * const uuid, std::string const &message, FILE* output) {
+	fprintf(output, "Error: %s\n", uuid);
+	fprintf(output, "Message: %s\n\n", SubstVar(SubstVar(message, "\n\n", "\n.\n"), "\n", "\n ").c_str());
+	return true;
+}
+									/*}}}*/
 // EDSP::ExecuteSolver - fork requested solver and setup ipc pipes	{{{*/
 // EDSP::ExecuteSolver - fork requested solver and setup ipc pipes	{{{*/
 bool EDSP::ExecuteSolver(const char* const solver, int *solver_in, int *solver_out) {
 bool EDSP::ExecuteSolver(const char* const solver, int *solver_in, int *solver_out) {
 	std::vector<std::string> const solverDirs = _config->FindVector("Dir::Bin::Solvers");
 	std::vector<std::string> const solverDirs = _config->FindVector("Dir::Bin::Solvers");

+ 6 - 1
apt-pkg/edsp.h

@@ -171,8 +171,13 @@ public:
 	 *
 	 *
 	 *  The first line of the message should be a short description
 	 *  The first line of the message should be a short description
 	 *  of the error so it can be used for dialog titles or alike
 	 *  of the error so it can be used for dialog titles or alike
+	 *
+	 *  \param uuid of this error message
+	 *  \param message is free form text to discribe the error
+	 *  \param output the front-end listens for error messages
 	 */
 	 */
-	bool static WriteError(std::string const &message, FILE* output);
+	bool static WriteError(char const * const uuid, std::string const &message, FILE* output);
+
 
 
 	/** \brief executes the given solver and returns the pipe ends
 	/** \brief executes the given solver and returns the pipe ends
 	 *
 	 *

+ 1 - 1
cmdline/apt-dump-solver.cc

@@ -46,5 +46,5 @@ int main(int argc,const char *argv[])					/*{{{*/
 	fclose(output);
 	fclose(output);
 	fclose(input);
 	fclose(input);
 
 
-	EDSP::WriteError("I am too dumb, i can just dump!", stdout);
+	EDSP::WriteError("ERR_JUST_DUMPING", "I am too dumb, i can just dump!\nPlease use one of my friends instead!", stdout);
 }
 }

+ 3 - 3
cmdline/apt-internal-solver.cc

@@ -158,16 +158,16 @@ int main(int argc,const char *argv[])					/*{{{*/
 
 
 	if (upgrade == true) {
 	if (upgrade == true) {
 		if (pkgAllUpgrade(CacheFile) == false) {
 		if (pkgAllUpgrade(CacheFile) == false) {
-			EDSP::WriteError("An upgrade error occured", output);
+			EDSP::WriteError("ERR_UNSOLVABLE_UPGRADE", "An upgrade error occured", output);
 			return 0;
 			return 0;
 		}
 		}
 	} else if (distUpgrade == true) {
 	} else if (distUpgrade == true) {
 		if (pkgDistUpgrade(CacheFile) == false) {
 		if (pkgDistUpgrade(CacheFile) == false) {
-			EDSP::WriteError("An dist-upgrade error occured", output);
+			EDSP::WriteError("ERR_UNSOLVABLE_DIST_UPGRADE", "An dist-upgrade error occured", output);
 			return 0;
 			return 0;
 		}
 		}
 	} else if (Fix.Resolve() == false) {
 	} else if (Fix.Resolve() == false) {
-		EDSP::WriteError("An error occured", output);
+		EDSP::WriteError("ERR_UNSOLVABLE", "An error occured", output);
 		return 0;
 		return 0;
 	}
 	}