]> granicus.if.org Git - icinga2/commitdiff
Improve error reporting for "icinga2 console"
authorGunnar Beutner <gunnar@beutner.name>
Tue, 10 Feb 2015 12:58:35 +0000 (13:58 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 10 Feb 2015 12:58:35 +0000 (13:58 +0100)
refs #8133

lib/cli/consolecommand.cpp

index 7e2c2c26ed99d68b380bcf90ffd549ebca211f7c..d8249ff2f91c25c40e87ad7a8a161e9f4dafd6fa 100644 (file)
@@ -130,16 +130,39 @@ incomplete:
                                DebugInfo di = ex.GetDebugInfo();
 
                                if (lines.find(di.Path) != lines.end()) {
-                                       int offset;
-
-                                       if (di.Path != fileName) {
-                                               std::cout << di.Path << ": " << lines[di.Path] << "\n";
-                                               offset = 2;
-                                       } else
-                                               offset = 4;
-
-                                       std::cout << String(di.Path.GetLength() + offset, ' ');
-                                       std::cout << String(di.FirstColumn, ' ') << String(di.LastColumn - di.FirstColumn + 1, '^') << "\n";
+                                       String text = lines[di.Path];
+
+                                       std::vector<String> ulines;
+                                       boost::algorithm::split(ulines, text, boost::is_any_of("\n"));
+
+                                       for (int i = 1; i <= ulines.size(); i++) {
+                                               int start, len;
+
+                                               if (i == di.FirstLine) {
+                                                       start = di.FirstColumn;
+                                                       if (start > 0)
+                                                               start--;
+                                               } else
+                                                       start = 0;
+
+                                               if (i == di.LastLine)
+                                                       len = di.LastColumn - di.FirstColumn + 1;
+                                               else
+                                                       len = ulines[i].GetLength();
+
+                                               int offset;
+
+                                               if (di.Path != fileName) {
+                                                       std::cout << di.Path << ": " << ulines[i - 1] << "\n";
+                                                       offset = 2;
+                                               } else
+                                                       offset = 4;
+
+                                               if (i >= di.FirstLine && i <= di.LastLine) {
+                                                       std::cout << String(di.Path.GetLength() + offset, ' ');
+                                                       std::cout << String(start, ' ') << String(len, '^') << "\n";
+                                               }
+                                       }
                                } else {
                                        ShowCodeFragment(std::cout, di);
                                }