MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _msg_error

Method _msg_error

editor/debugger/script_editor_debugger.cpp:609–755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

607}
608
609void ScriptEditorDebugger::_msg_error(uint64_t p_thread_id, const Array &p_data) {
610 DebuggerMarshalls::OutputError oe;
611 ERR_FAIL_COND_MSG(oe.deserialize(p_data) == false, "Failed to deserialize error message");
612
613 // Format time.
614 Array time_vals = { oe.hr, oe.min, oe.sec, oe.msec };
615 bool e;
616 String time = String("%d:%02d:%02d:%03d").sprintf(time_vals, &e);
617
618 // Rest of the error data.
619 bool source_is_project_file = oe.source_file.begins_with("res://");
620
621 // Metadata to highlight error line in scripts.
622 Array source_meta = { oe.source_file, oe.source_line };
623
624 // Create error tree to display above error or warning details.
625 TreeItem *r = error_tree->get_root();
626 if (!r) {
627 r = error_tree->create_item();
628 }
629
630 // Also provide the relevant details as tooltip to quickly check without
631 // uncollapsing the tree.
632 String tooltip = oe.warning ? TTR("Warning:") : TTR("Error:");
633
634 TreeItem *error = error_tree->create_item(r);
635 if (oe.warning) {
636 error->set_meta("_is_warning", true);
637 } else {
638 error->set_meta("_is_error", true);
639 }
640 error->set_collapsed(true);
641
642 error->set_icon(0, get_editor_theme_icon(oe.warning ? SNAME("Warning") : SNAME("Error")));
643 error->set_text(0, time);
644 error->set_text_alignment(0, HORIZONTAL_ALIGNMENT_LEFT);
645
646 const Color color = get_theme_color(oe.warning ? SNAME("warning_color") : SNAME("error_color"), EditorStringName(Editor));
647 error->set_custom_color(0, color);
648 error->set_custom_color(1, color);
649
650 String error_title;
651 if (!oe.source_func.is_empty() && source_is_project_file) {
652 // If source function is inside the project file.
653 error_title += oe.source_func + ": ";
654 } else if (oe.callstack.size() > 0) {
655 // Otherwise, if available, use the script's stack in the error title.
656 error_title = _format_frame_text(&oe.callstack[0]) + ": ";
657 } else if (!oe.source_func.is_empty()) {
658 // Otherwise try to use the C++ source function.
659 error_title += oe.source_func + ": ";
660 }
661 // If we have a (custom) error message, use it as title, and add a C++ Error
662 // item with the original error condition.
663 error_title += oe.error_descr.is_empty() ? oe.error : oe.error_descr;
664 error->set_text(1, error_title);
665 error->set_autowrap_mode(1, TextServer::AUTOWRAP_WORD_SMART);
666 tooltip += " " + error_title + "\n";

Callers

nothing calls this directly

Calls 15

TTRFunction · 0.85
get_languageFunction · 0.85
vformatFunction · 0.85
itosFunction · 0.85
sprintfMethod · 0.80
begins_withMethod · 0.80
set_custom_colorMethod · 0.80
set_metadataMethod · 0.80
ends_withMethod · 0.80
sizeMethod · 0.65
StringClass · 0.50
deserializeMethod · 0.45

Tested by

no test coverage detected