Skip to content

Commit 78fefbf

Browse files
authored
Label discord notifications with "Fatal" or "Recoverable" (#673)
* fire off send_fatal_notification() on unrecoverable errors for ScreenshotException. * add send_recoverable_notification() * fix typo * minor change * update title for send_program_notification()
1 parent ee65bb0 commit 78fefbf

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,20 @@ std::shared_ptr<const ImageRGB32> ScreenshotException::screenshot() const{
8585
}
8686

8787

88-
void ScreenshotException::send_notification(ProgramEnvironment& env, EventNotificationOption& notification) const{
88+
void ScreenshotException::send_notification(ProgramEnvironment& env, EventNotificationOption& notification, const std::string& title_prefix) const{
8989
std::vector<std::pair<std::string, std::string>> embeds;
9090
if (!m_message.empty()){
9191
embeds.emplace_back(std::pair<std::string, std::string>("Message:", m_message));
9292
}
9393

94+
std::string title = title_prefix;
95+
title.append(name());
96+
9497
if (m_send_error_report == ErrorReport::SEND_ERROR_REPORT){
9598
report_error(
9699
&env.logger(),
97100
env.program_info(),
98-
name(),
101+
title,
99102
embeds,
100103
screenshot_view(),
101104
m_stream ? &m_stream->history() : nullptr
@@ -105,12 +108,33 @@ void ScreenshotException::send_notification(ProgramEnvironment& env, EventNotifi
105108
send_program_notification(
106109
env, notification,
107110
color(),
108-
name(),
111+
title,
109112
std::move(embeds), "",
110113
screenshot_view()
111114
);
112115
}
113116

117+
void ScreenshotException::send_recoverable_notification(ProgramEnvironment& env) const{
118+
EventNotificationOption recoverable_notification = EventNotificationOption(
119+
"Program Error (Recoverable)",
120+
true, true,
121+
ImageAttachmentMode::JPG,
122+
{"Notifs"}
123+
);
124+
125+
send_notification(env, recoverable_notification, "Recoverable: ");
126+
}
127+
128+
void ScreenshotException::send_fatal_notification(ProgramEnvironment& env) const{
129+
EventNotificationOption fatal_notification = EventNotificationOption(
130+
"Program Error (Fatal)",
131+
true, true,
132+
ImageAttachmentMode::JPG,
133+
{"Notifs"}
134+
);
135+
136+
send_notification(env, fatal_notification, "Fatal: ");
137+
}
114138

115139

116140

SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class ScreenshotException : public Exception{
7171
std::shared_ptr<const ImageRGB32> screenshot() const;
7272

7373
virtual Color color() const{ return COLOR_RED; }
74-
virtual void send_notification(ProgramEnvironment& env, EventNotificationOption& notification) const;
74+
virtual void send_notification(ProgramEnvironment& env, EventNotificationOption& notification, const std::string& title_prefix = "") const;
75+
void send_recoverable_notification(ProgramEnvironment& env) const;
76+
void send_fatal_notification(ProgramEnvironment& env) const;
7577

7678
public:
7779
ErrorReport m_send_error_report;

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void MultiSwitchProgramSession::internal_run_program(){
233233
message = e.name();
234234
}
235235
report_error(message);
236-
e.send_notification(env, m_option.instance().NOTIFICATION_ERROR_FATAL);
236+
e.send_fatal_notification(env);
237237
}catch (Exception& e){
238238
logger().log("Program stopped with an exception!", COLOR_RED);
239239
env.add_overlay_log_to_all_consoles("- Program Error -", COLOR_RED);

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void SingleSwitchProgramSession::internal_run_program(){
194194
message = e.name();
195195
}
196196
report_error(message);
197-
e.send_notification(env, m_option.instance().NOTIFICATION_ERROR_FATAL);
197+
e.send_fatal_notification(env);
198198
}catch (Exception& e){
199199
logger().log("Program stopped with an exception!", COLOR_RED);
200200
env.console.overlay().add_log("- Program Error -", COLOR_RED);

SerialPrograms/Source/PokemonSV/Programs/Eggs/PokemonSV_EggAutonomous.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,6 @@ bool EggAutonomous::handle_recoverable_error(
767767
auto& stats = env.current_stats<EggAutonomous_Descriptor::Stats>();
768768
stats.m_errors++;
769769
env.update_stats();
770-
e.send_notification(env, notification);
771770

772771
if (SAVE_DEBUG_VIDEO){
773772
// Take a video to give more context for debugging
@@ -797,6 +796,7 @@ bool EggAutonomous::handle_recoverable_error(
797796
env.console
798797
);
799798
}
799+
e.send_recoverable_notification(env);
800800

801801
env.log("Reset game to handle recoverable error");
802802
reset_game(env.program_info(), env.console, context);

0 commit comments

Comments
 (0)