MCPcopy Create free account
hub / github.com/duckdb/duckdb / PrintError

Method PrintError

tools/shell/shell_highlight.cpp:160–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160void ShellHighlight::PrintError(string error_msg) {
161 if (error_msg.empty()) {
162 return;
163 }
164 vector<duckdb::SimplifiedToken> tokens;
165 string error_type;
166 auto error_location = duckdb::StringUtil::Find(error_msg, "Error: ");
167 if (error_location.IsValid()) {
168 error_type = error_msg.substr(0, error_location.GetIndex() + 6);
169 error_msg = error_msg.substr(error_location.GetIndex() + 7);
170 }
171 try {
172 tokens = duckdb::Parser::TokenizeError(error_msg);
173 } catch (...) {
174 // fallback
175 state.Print(PrintOutput::STDERR, error_msg.c_str());
176 state.Print(PrintOutput::STDERR, "\n");
177 return;
178 }
179 if (!tokens.empty() && tokens[0].start > 0) {
180 duckdb::SimplifiedToken new_token;
181 new_token.type = duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_IDENTIFIER;
182 new_token.start = 0;
183 tokens.insert(tokens.begin(), new_token);
184 }
185 if (tokens.empty() && !error_msg.empty()) {
186 duckdb::SimplifiedToken new_token;
187 new_token.type = duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_IDENTIFIER;
188 new_token.start = 0;
189 tokens.push_back(new_token);
190 }
191 if (!error_type.empty()) {
192 PrintText(error_type + "\n", PrintOutput::STDERR, HighlightElementType::ERROR_EMPHASIS);
193 }
194 for (idx_t i = 0; i < tokens.size(); i++) {
195 HighlightElementType element_type = HighlightElementType::NONE;
196 switch (tokens[i].type) {
197 case duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_IDENTIFIER:
198 break;
199 case duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_ERROR:
200 element_type = HighlightElementType::ERROR_TOKEN;
201 break;
202 case duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_ERROR_EMPHASIS:
203 element_type = HighlightElementType::ERROR_EMPHASIS;
204 break;
205 case duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_ERROR_SUGGESTION:
206 element_type = HighlightElementType::ERROR_SUGGESTION;
207 break;
208 case duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_NUMERIC_CONSTANT:
209 element_type = HighlightElementType::NUMERIC_CONSTANT;
210 break;
211 case duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_STRING_CONSTANT:
212 element_type = HighlightElementType::STRING_CONSTANT;
213 break;
214 case duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_OPERATOR:
215 break;
216 case duckdb::SimplifiedTokenType::SIMPLIFIED_TOKEN_KEYWORD:
217 element_type = HighlightElementType::KEYWORD;

Callers 1

PrintDatabaseErrorMethod · 0.80

Calls 10

FindFunction · 0.85
c_strMethod · 0.80
emptyMethod · 0.45
IsValidMethod · 0.45
GetIndexMethod · 0.45
PrintMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected