Skip to content

Commit 7d8a47f

Browse files
authored
chore: Error logging improvments (#713)
1 parent 20e25e4 commit 7d8a47f

3 files changed

Lines changed: 89 additions & 18 deletions

File tree

objects/obj_main_menu/Create_0.gml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ if (!instance_exists(obj_cuicons)){
55
}
66

77
global.save_version=0;
8-
global.game_seed=0;
98
global.cheat_req=false;
109
global.cheat_gene=false;
1110
global.cheat_disp=false;

scripts/__init_global/__init_global.gml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ function __init_global() {
77
draw_set_colour(c_black);
88

99
initialize_marine_traits();
10+
11+
global.chapter_name = "None";
12+
global.game_seed = 0;
1013
}

scripts/scr_log/scr_log.gml

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88
/// @param {string} _message - The message to log.
99
function create_error_file(_message) {
1010
if (string_length(_message) > 0) {
11-
var _date_time = $"{DATE_TIME_1}";
12-
var _log_file = file_text_open_write("Logs/" + $"{_date_time}_error.log");
11+
var _log_file = file_text_open_write($"Logs/{DATE_TIME_1}_error.log");
1312
file_text_write_string(_log_file, _message);
1413
file_text_close(_log_file);
1514
}
15+
copy_last_messages_file();
16+
}
17+
18+
/// @description Creates a copy of the last_messages.log file, with the current date in the name, in the same folder.
19+
function copy_last_messages_file() {
20+
if (file_exists(PATH_last_messages)) {
21+
file_copy(PATH_last_messages, $"Logs/{DATE_TIME_1}_messages.log");
22+
}
1623
}
1724

1825
/// @description Displays a popup, logs the error into file, and copies to clipboard.
@@ -23,31 +30,66 @@ function create_error_file(_message) {
2330
/// @param {string} _report_title - Optional. Preset title for the bug report.
2431
function handle_error(_header, _message, _stacktrace="", _critical = false, _report_title="") {
2532
var _full_message = "";
26-
_full_message += $"{LB_92}\n";
27-
_full_message += $"{_header}\n\n";
28-
_full_message += $"Date-Time: {DATE_TIME_3}\n";
29-
_full_message += $"Game Version: {global.game_version}\n";
30-
_full_message += $"Build Date: {global.build_date}\n";
31-
_full_message += $"Commit Hash: {global.commit_hash}\n\n";
32-
_full_message += $"Details:\n";
33-
_full_message += $"{_message}\n\n";
34-
_full_message += $"Stacktrace:\n";
35-
_full_message += $"{_stacktrace}\n";
36-
_full_message += $"{LB_92}";
33+
var _header_section = "";
34+
var _info_section = "";
35+
var _save_section = "";
36+
var _error_section = "";
37+
var _footer_section = "";
38+
39+
_header_section += $"{LB_92}\n";
40+
_header_section += $"{_header}\n\n";
41+
_full_message += _header_section;
42+
43+
// _info_section += $"Operating System: {os_type_format(os_type)}\n"; // Uncomment this when we start compiling for different platforms;
44+
_info_section += $"Date-Time: {DATE_TIME_3}\n";
45+
_info_section += $"Game Version: {global.game_version}\n";
46+
_info_section += $"Build Date: {global.build_date}\n";
47+
_info_section += $"Commit Hash: {global.commit_hash}\n\n";
48+
_full_message += _info_section;
49+
50+
if (global.chapter_name != "None") {
51+
_save_section += $"Chapter Name: {global.chapter_name}\n";
52+
}
53+
if (instance_exists(obj_controller)) {
54+
_save_section += $"Current Turn: {obj_controller.turn}\n";
55+
}
56+
if (global.game_seed != 0) {
57+
_save_section += $"Game Seed: {global.game_seed}\n";
58+
}
59+
if (_save_section != "") {
60+
_full_message += "Save Details:\n";
61+
_full_message += $"{_save_section}\n";
62+
}
63+
64+
_error_section += "Error Details:\n";
65+
_error_section += $"{_message}\n\n";
66+
_error_section += "Stacktrace:\n";
67+
_error_section += $"{_stacktrace}\n";
68+
_full_message += _error_section;
69+
70+
_footer_section += $"{LB_92}";
71+
_full_message += _footer_section;
3772

3873
if (_report_title != "") {
3974
_report_title += "\n";
4075
}
4176

42-
var _commit_history_link = $"https://github.com/Adeptus-Dominus/ChapterMaster/commits/{global.commit_hash}";
77+
var _error_file_text = $"{_report_title}{_full_message}";
78+
var _commit_history_link = "";
79+
if (global.commit_hash != "unknown hash") {
80+
_commit_history_link = $"https://github.com/Adeptus-Dominus/ChapterMaster/commits/{global.commit_hash}";
81+
_error_file_text += $"\n{_commit_history_link}";
82+
}
4383

44-
create_error_file($"{_report_title}{_full_message}\n{_commit_history_link}");
45-
show_debug_message(_full_message);
84+
create_error_file(_error_file_text);
85+
show_debug_message($"{_header_section}{_error_section}{_footer_section}");
4686

4787
var _clipboard_message = "";
4888
_clipboard_message += $"{_report_title}";
4989
_clipboard_message += $"{markdown_codeblock(_full_message, "log")}\n";
50-
_clipboard_message += $"{_commit_history_link}";
90+
if (_commit_history_link != "") {
91+
_clipboard_message += $"\n{_commit_history_link}";
92+
}
5193
clipboard_set_text(_clipboard_message);
5294

5395
var _player_message = "";
@@ -146,3 +188,30 @@ function clean_stacktrace_line(_stacktrace_line) {
146188

147189
return _stacktrace_line;
148190
}
191+
192+
/// @description Formats the GM constant to a readable OS name.
193+
/// @param {string} _os_type - GM constant for the OS.
194+
/// @returns {string}
195+
function os_type_format(_os_type) {
196+
var _os_type_dictionary = {
197+
os_windows: "Windows OS",
198+
os_gxgames: "GX.games",
199+
os_linux: "Linux",
200+
os_macosx: "macOS X",
201+
os_ios: "iOS",
202+
os_tvos: "Apple tvOS",
203+
os_android: "Android",
204+
os_ps4: "Sony PlayStation 4",
205+
os_ps5: "Sony PlayStation 5",
206+
os_gdk: "Microsoft GDK",
207+
os_xboxseriesxs: "Xbox Series X/S",
208+
os_switch: "Nintendo Switch",
209+
os_unknown: "Unknown OS"
210+
};
211+
212+
if (struct_exists(_os_type_dictionary, _os_type)) {
213+
return _os_type_dictionary[$ _os_type];
214+
} else {
215+
return _os_type_dictionary.os_unknown;
216+
}
217+
}

0 commit comments

Comments
 (0)