| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/gn/err.h" | 5 #include "tools/gn/err.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
| 10 #include "tools/gn/input_file.h" | 10 #include "tools/gn/input_file.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 void Err::InternalPrintToStdout(bool is_sub_err) const { | 156 void Err::InternalPrintToStdout(bool is_sub_err) const { |
| 157 DCHECK(has_error_); | 157 DCHECK(has_error_); |
| 158 | 158 |
| 159 if (!is_sub_err) | 159 if (!is_sub_err) |
| 160 OutputString("ERROR ", DECORATION_RED); | 160 OutputString("ERROR ", DECORATION_RED); |
| 161 | 161 |
| 162 // File name and location. | 162 // File name and location. |
| 163 const InputFile* input_file = location_.file(); | 163 const InputFile* input_file = location_.file(); |
| 164 std::string loc_str; | 164 std::string loc_str = location_.Describe(true); |
| 165 if (input_file) { | 165 if (!loc_str.empty()) { |
| 166 std::string name; | 166 if (is_sub_err) |
| 167 if (input_file->friendly_name().empty()) | 167 loc_str.insert(0, "See "); |
| 168 name = input_file->name().value(); | |
| 169 else | 168 else |
| 170 name = input_file->friendly_name(); | 169 loc_str.insert(0, "at "); |
| 171 | 170 loc_str.append(": "); |
| 172 if (is_sub_err) | |
| 173 loc_str = "See "; | |
| 174 else | |
| 175 loc_str = "at "; | |
| 176 loc_str += name + ": " + | |
| 177 base::IntToString(location_.line_number()) + ":" + | |
| 178 base::IntToString(location_.char_offset()) + ": "; | |
| 179 } | 171 } |
| 180 OutputString(loc_str + message_ + "\n"); | 172 OutputString(loc_str + message_ + "\n"); |
| 181 | 173 |
| 182 // Quoted line. | 174 // Quoted line. |
| 183 if (input_file) { | 175 if (input_file) { |
| 184 std::string line = GetNthLine(input_file->contents(), | 176 std::string line = GetNthLine(input_file->contents(), |
| 185 location_.line_number()); | 177 location_.line_number()); |
| 186 if (!ContainsOnlyWhitespaceASCII(line)) { | 178 if (!ContainsOnlyWhitespaceASCII(line)) { |
| 187 OutputString(line + "\n", DECORATION_BOLD); | 179 OutputString(line + "\n", DECORATION_BOLD); |
| 188 OutputHighlighedPosition(location_, ranges_, line.size()); | 180 OutputHighlighedPosition(location_, ranges_, line.size()); |
| 189 } | 181 } |
| 190 } | 182 } |
| 191 | 183 |
| 192 // Optional help text. | 184 // Optional help text. |
| 193 if (!help_text_.empty()) | 185 if (!help_text_.empty()) |
| 194 OutputString(help_text_ + "\n"); | 186 OutputString(help_text_ + "\n"); |
| 195 | 187 |
| 196 // Sub errors. | 188 // Sub errors. |
| 197 for (size_t i = 0; i < sub_errs_.size(); i++) | 189 for (size_t i = 0; i < sub_errs_.size(); i++) |
| 198 sub_errs_[i].InternalPrintToStdout(true); | 190 sub_errs_[i].InternalPrintToStdout(true); |
| 199 } | 191 } |
| OLD | NEW |