mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2026-08-29 09:26:53 +01:00
stuff
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
// Settings for the error handler and error viewer
|
||||
|
||||
#define ERROR_COOLDOWN 600 // The "cooldown" time for each occurrence of a unique error
|
||||
#define ERROR_LIMIT 9 // How many occurrences before the next will silence them
|
||||
#define ERROR_MAX_COOLDOWN (ERROR_COOLDOWN * ERROR_LIMIT)
|
||||
#define ERROR_SILENCE_TIME 6000 // How long a unique error will be silenced for
|
||||
|
||||
// How long to wait between messaging admins about occurrences of a unique error
|
||||
#define ERROR_MSG_DELAY 50
|
||||
@@ -3,7 +3,6 @@ GLOBAL_VAR_INIT(total_runtimes_skipped, 0)
|
||||
|
||||
#ifdef USE_CUSTOM_ERROR_HANDLER
|
||||
#define ERROR_USEFUL_LEN 2
|
||||
|
||||
/world/Error(exception/E, datum/e_src)
|
||||
GLOB.total_runtimes++
|
||||
|
||||
@@ -19,6 +18,13 @@ GLOBAL_VAR_INIT(total_runtimes_skipped, 0)
|
||||
log_world("The bug with recursion runtimes has been fixed. Please remove the snowflake check from world/Error in [__FILE__]:[__LINE__]")
|
||||
return //this will never happen.
|
||||
|
||||
else if(copytext(E.name,1,18) == "Out of resources!")
|
||||
log_world("BYOND out of memory. Restarting")
|
||||
log_game("BYOND out of memory. Restarting")
|
||||
TgsEndProcess()
|
||||
Reboot(reason = 1)
|
||||
return ..()
|
||||
|
||||
if (islist(stack_trace_storage))
|
||||
for (var/line in splittext(E.desc, "\n"))
|
||||
if (text2ascii(line) != 32)
|
||||
@@ -46,10 +52,28 @@ GLOBAL_VAR_INIT(total_runtimes_skipped, 0)
|
||||
//Handle cooldowns and silencing spammy errors
|
||||
var/silencing = FALSE
|
||||
|
||||
var/configured_error_cooldown = ERROR_COOLDOWN
|
||||
var/configured_error_limit = ERROR_LIMIT
|
||||
var/configured_error_silence_time = ERROR_SILENCE_TIME
|
||||
var/configured_error_cooldown = 600
|
||||
var/configured_error_limit = 50
|
||||
var/configured_error_silence_time = 6000
|
||||
|
||||
/*
|
||||
// We can runtime before config is initialized because BYOND initialize objs/map before a bunch of other stuff happens.
|
||||
// This is a bunch of workaround code for that. Hooray!
|
||||
var/configured_error_cooldown
|
||||
var/configured_error_limit
|
||||
var/configured_error_silence_time
|
||||
if(config && config.entries)
|
||||
configured_error_cooldown = CONFIG_GET(number/error_cooldown)
|
||||
configured_error_limit = CONFIG_GET(number/error_limit)
|
||||
configured_error_silence_time = CONFIG_GET(number/error_silence_time)
|
||||
else
|
||||
var/datum/config_entry/CE = /datum/config_entry/number/error_cooldown
|
||||
configured_error_cooldown = initial(CE.config_entry_value)
|
||||
CE = /datum/config_entry/number/error_limit
|
||||
configured_error_limit = initial(CE.config_entry_value)
|
||||
CE = /datum/config_entry/number/error_silence_time
|
||||
configured_error_silence_time = initial(CE.config_entry_value)
|
||||
*/
|
||||
|
||||
//Each occurence of a unique error adds to its cooldown time...
|
||||
cooldown = max(0, cooldown - (world.time - last_seen)) + configured_error_cooldown
|
||||
@@ -64,7 +88,7 @@ GLOBAL_VAR_INIT(total_runtimes_skipped, 0)
|
||||
error_cooldown[erroruid] = 0
|
||||
if(skipcount > 0)
|
||||
SEND_TEXT(world.log, "\[[time_stamp()]] Skipped [skipcount] runtimes in [E.file],[E.line].")
|
||||
error_cache.logError(E, skip_count = skipcount)
|
||||
GLOB.error_cache.log_error(E, skip_count = skipcount)
|
||||
|
||||
error_last_seen[erroruid] = world.time
|
||||
error_cooldown[erroruid] = cooldown
|
||||
@@ -93,12 +117,12 @@ GLOBAL_VAR_INIT(total_runtimes_skipped, 0)
|
||||
desclines += (" " + line) // Pad any unpadded lines, so they look pretty
|
||||
else
|
||||
desclines += line
|
||||
if(usrinfo) //If this info isn't null, it hasn't been added yet
|
||||
if(usrinfo) //If thi s info isn't null, it hasn't been added yet
|
||||
desclines.Add(usrinfo)
|
||||
if(silencing)
|
||||
desclines += " (This error will now be silenced for [DisplayTimeText(configured_error_silence_time)])"
|
||||
if(error_cache)
|
||||
error_cache.logError(E, desclines)
|
||||
if(GLOB.error_cache)
|
||||
GLOB.error_cache.log_error(E, desclines)
|
||||
|
||||
var/main_line = "\[[time_stamp()]] Runtime in [E.file],[E.line]: [E]"
|
||||
SEND_TEXT(world.log, main_line)
|
||||
@@ -111,6 +135,7 @@ GLOBAL_VAR_INIT(total_runtimes_skipped, 0)
|
||||
GLOB.current_test.Fail("[main_line]\n[desclines.Join("\n")]")
|
||||
#endif
|
||||
|
||||
|
||||
// This writes the regular format (unwrapping newlines and inserting timestamps as needed).
|
||||
log_error("runtime error: [E.name]\n[E.desc]")
|
||||
log_runtime("runtime error: [E.name]\n[E.desc]")
|
||||
#endif
|
||||
|
||||
@@ -3,204 +3,196 @@
|
||||
|
||||
// There are 3 different types used here:
|
||||
//
|
||||
// - ErrorCache keeps track of all error sources, as well as all individually
|
||||
// - error_cache keeps track of all error sources, as well as all individually
|
||||
// logged errors. Only one instance of this datum should ever exist, and it's
|
||||
// right here:
|
||||
|
||||
#ifdef DEBUG
|
||||
var/global/datum/ErrorViewer/ErrorCache/error_cache = new()
|
||||
#ifdef USE_CUSTOM_ERROR_HANDLER
|
||||
GLOBAL_DATUM_INIT(error_cache, /datum/error_viewer/error_cache, new)
|
||||
#else
|
||||
// If debugging is disabled, there's nothing useful to log, so don't bother.
|
||||
var/global/datum/ErrorViewer/ErrorCache/error_cache = null
|
||||
GLOBAL_DATUM(error_cache, /datum/error_viewer/error_cache)
|
||||
#endif
|
||||
|
||||
// - ErrorSource datums exist for each line (of code) that generates an error,
|
||||
// - error_source datums exist for each line (of code) that generates an error,
|
||||
// and keep track of all errors generated by that line.
|
||||
//
|
||||
// - ErrorEntry datums exist for each logged error, and keep track of all
|
||||
// - error_entry datums exist for each logged error, and keep track of all
|
||||
// relevant info about that error.
|
||||
|
||||
// Common vars and procs are kept at the ErrorViewer level
|
||||
/datum/ErrorViewer/
|
||||
// Common vars and procs are kept at the error_viewer level
|
||||
/datum/error_viewer
|
||||
var/name = ""
|
||||
|
||||
/datum/ErrorViewer/proc/browseTo(var/user, var/html)
|
||||
if(user)
|
||||
var/datum/browser/popup = new(user, "error_viewer", "Runtime Viewer", 700, 500)
|
||||
popup.add_head_content({"<style>
|
||||
.runtime{
|
||||
background-color: #171717;
|
||||
border: solid 1px #202020;
|
||||
font-family:'Courier New',monospace;
|
||||
font-size:9pt;
|
||||
color: #DDDDDD;
|
||||
}
|
||||
p.runtime_list{
|
||||
font-family:'Courier New',monospace;
|
||||
font-size:9pt;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
text-indent:-13ch;
|
||||
margin-left:13ch;
|
||||
}
|
||||
</style>"})
|
||||
popup.set_content(html)
|
||||
popup.open(0)
|
||||
/datum/error_viewer/proc/browse_to(client/user, html)
|
||||
var/datum/browser/browser = new(ismob(user)? user : user.mob, "error_viewer", null, 600, 400)
|
||||
browser.set_content(html)
|
||||
browser.add_head_content({"
|
||||
<style>
|
||||
.runtime
|
||||
{
|
||||
background-color: #171717;
|
||||
border: solid 1px #202020;
|
||||
font-family: "Courier New";
|
||||
padding-left: 10px;
|
||||
color: #CCCCCC;
|
||||
}
|
||||
.runtime_line
|
||||
{
|
||||
margin-bottom: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
"})
|
||||
browser.open()
|
||||
|
||||
/datum/ErrorViewer/proc/buildHeader(var/datum/ErrorViewer/back_to, var/linear, var/refreshable)
|
||||
// Common starter HTML for showTo
|
||||
var/html = ""
|
||||
/datum/error_viewer/proc/build_header(datum/error_viewer/back_to, linear)
|
||||
// Common starter HTML for show_to
|
||||
|
||||
if(istype(back_to))
|
||||
html += "[back_to.makeLink("<<<", null, linear)] "
|
||||
if(refreshable)
|
||||
html += "[makeLink("Refresh", null, linear)]"
|
||||
if(html)
|
||||
html += "<br><br>"
|
||||
return html
|
||||
. = ""
|
||||
|
||||
/datum/ErrorViewer/proc/showTo(var/user, var/datum/ErrorViewer/back_to, var/linear)
|
||||
if (istype(back_to))
|
||||
. += back_to.make_link("<b><<<</b>", null, linear)
|
||||
|
||||
. += "[make_link("Refresh")]<br><br>"
|
||||
|
||||
/datum/error_viewer/proc/show_to(user, datum/error_viewer/back_to, linear)
|
||||
// Specific to each child type
|
||||
return
|
||||
|
||||
/datum/ErrorViewer/proc/makeLink(var/linktext, var/datum/ErrorViewer/back_to, var/linear)
|
||||
/datum/error_viewer/proc/make_link(linktext, datum/error_viewer/back_to, linear)
|
||||
var/back_to_param = ""
|
||||
if(!linktext)
|
||||
if (!linktext)
|
||||
linktext = name
|
||||
if(istype(back_to))
|
||||
back_to_param = ";viewruntime_backto=\ref[back_to]"
|
||||
if(linear)
|
||||
|
||||
if (istype(back_to))
|
||||
back_to_param = ";viewruntime_backto=[REF(back_to)]"
|
||||
|
||||
if (linear)
|
||||
back_to_param += ";viewruntime_linear=1"
|
||||
return "<A HREF='?src=\ref[src];viewruntime=\ref[src][back_to_param]'>[html_encode(linktext)]</A>"
|
||||
|
||||
/datum/ErrorViewer/Topic(href, href_list)
|
||||
if(..())
|
||||
return 1
|
||||
if(href_list["viewruntime_backto"])
|
||||
showTo(usr, locate(href_list["viewruntime_backto"]), href_list["viewruntime_linear"])
|
||||
else
|
||||
showTo(usr, null, href_list["viewruntime_linear"])
|
||||
return "<a href='?_src_=holder;[HrefToken()];viewruntime=[REF(src)][back_to_param]'>[linktext]</a>"
|
||||
|
||||
/datum/ErrorViewer/ErrorCache
|
||||
/datum/error_viewer/error_cache
|
||||
var/list/errors = list()
|
||||
var/list/error_sources = list()
|
||||
var/list/errors_silenced = list()
|
||||
|
||||
/datum/ErrorViewer/ErrorCache/showTo(var/user, var/datum/ErrorViewer/back_to, var/linear)
|
||||
var/html = buildHeader(null, linear, refreshable=1)
|
||||
html += "[GLOB.total_runtimes] runtimes, [GLOB.total_runtimes_skipped] skipped<br><br>"
|
||||
if(!linear)
|
||||
html += "organized | [makeLink("linear", null, 1)]<hr>"
|
||||
var/datum/ErrorViewer/ErrorSource/error_source
|
||||
for(var/erroruid in error_sources)
|
||||
/datum/error_viewer/error_cache/show_to(user, datum/error_viewer/back_to, linear)
|
||||
var/html = build_header()
|
||||
html += "<b>[GLOB.total_runtimes]</b> runtimes, <b>[GLOB.total_runtimes_skipped]</b> skipped<br><br>"
|
||||
if (!linear)
|
||||
html += "organized | [make_link("linear", null, 1)]<hr>"
|
||||
var/datum/error_viewer/error_source/error_source
|
||||
for (var/erroruid in error_sources)
|
||||
error_source = error_sources[erroruid]
|
||||
html += "<p class='runtime_list'>[error_source.makeLink(null, src)]<br></p>"
|
||||
else
|
||||
html += "[makeLink("organized", null)] | linear<hr>"
|
||||
for(var/datum/ErrorViewer/ErrorEntry/error_entry in errors)
|
||||
html += "<p class='runtime_list'>[error_entry.makeLink(null, src, 1)]<br></p>"
|
||||
browseTo(user, html)
|
||||
html += "[error_source.make_link(null, src)]<br>"
|
||||
|
||||
/datum/ErrorViewer/ErrorCache/proc/logError(var/exception/e, var/list/desclines, var/skipCount, var/datum/e_src)
|
||||
if(!istype(e))
|
||||
else
|
||||
html += "[make_link("organized", null)] | linear<hr>"
|
||||
for (var/datum/error_viewer/error_entry/error_entry in errors)
|
||||
html += "[error_entry.make_link(null, src, 1)]<br>"
|
||||
|
||||
browse_to(user, html)
|
||||
|
||||
/datum/error_viewer/error_cache/proc/log_error(exception/e, list/desclines, skip_count)
|
||||
if (!istype(e))
|
||||
return // Abnormal exception, don't even bother
|
||||
|
||||
var/erroruid = "[e.file][e.line]"
|
||||
var/datum/ErrorViewer/ErrorSource/error_source = error_sources[erroruid]
|
||||
if(!error_source)
|
||||
var/datum/error_viewer/error_source/error_source = error_sources[erroruid]
|
||||
if (!error_source)
|
||||
error_source = new(e)
|
||||
error_sources[erroruid] = error_source
|
||||
|
||||
var/datum/ErrorViewer/ErrorEntry/error_entry = new(e, desclines, skipCount, e_src)
|
||||
var/datum/error_viewer/error_entry/error_entry = new(e, desclines, skip_count)
|
||||
error_entry.error_source = error_source
|
||||
errors += error_entry
|
||||
error_source.errors += error_entry
|
||||
if(skipCount)
|
||||
return // Skip notifying admins about skipped errors
|
||||
if (skip_count)
|
||||
return // Skip notifying admins about skipped errors.
|
||||
|
||||
// Show the error to admins with debug messages turned on, but only if one
|
||||
// from the same source hasn't been shown too recently
|
||||
// (Also, make sure config is initialized, or log_debug will runtime)
|
||||
if(config && error_source.next_message_at <= world.time)
|
||||
if (error_source.next_message_at <= world.time)
|
||||
var/const/viewtext = "\[view]" // Nesting these in other brackets went poorly
|
||||
log_debug("Runtime in [e.file],[e.line]: [html_encode(e.name)] [error_entry.makeLink(viewtext)]")
|
||||
error_source.next_message_at = world.time + ERROR_MSG_DELAY
|
||||
//log_debug("Runtime in <b>[e.file]</b>, line <b>[e.line]</b>: <b>[html_encode(e.name)]</b> [error_entry.make_link(viewtext)]")
|
||||
/*
|
||||
var/err_msg_delay
|
||||
if(config)
|
||||
err_msg_delay = CONFIG_GET(number/error_msg_delay)
|
||||
else
|
||||
var/datum/config_entry/CE = /datum/config_entry/number/error_msg_delay
|
||||
err_msg_delay = initial(CE.config_entry_value)
|
||||
*/
|
||||
var/err_msg_delay = 50
|
||||
error_source.next_message_at = world.time + err_msg_delay
|
||||
|
||||
/datum/ErrorViewer/ErrorSource
|
||||
/datum/error_viewer/error_source
|
||||
var/list/errors = list()
|
||||
var/next_message_at = 0
|
||||
|
||||
/datum/ErrorViewer/ErrorSource/New(var/exception/e)
|
||||
if(!istype(e))
|
||||
/datum/error_viewer/error_source/New(exception/e)
|
||||
if (!istype(e))
|
||||
name = "\[[time_stamp()]] Uncaught exceptions"
|
||||
return
|
||||
name = "\[[time_stamp()]] Runtime in [e.file],[e.line]: [e]"
|
||||
|
||||
/datum/ErrorViewer/ErrorSource/showTo(var/user, var/datum/ErrorViewer/back_to, var/linear)
|
||||
if(!istype(back_to))
|
||||
back_to = error_cache
|
||||
var/html = buildHeader(back_to, refreshable=1)
|
||||
for(var/datum/ErrorViewer/ErrorEntry/error_entry in errors)
|
||||
html += "<p class='runtime_list'>[error_entry.makeLink(null, src)]<br></p>"
|
||||
browseTo(user, html)
|
||||
name = "<b>\[[time_stamp()]]</b> Runtime in <b>[e.file]</b>, line <b>[e.line]</b>: <b>[html_encode(e.name)]</b>"
|
||||
|
||||
/datum/ErrorViewer/ErrorEntry
|
||||
var/datum/ErrorViewer/ErrorSource/error_source
|
||||
/datum/error_viewer/error_source/show_to(user, datum/error_viewer/back_to, linear)
|
||||
if (!istype(back_to))
|
||||
back_to = GLOB.error_cache
|
||||
|
||||
var/html = build_header(back_to)
|
||||
for (var/datum/error_viewer/error_entry/error_entry in errors)
|
||||
html += "[error_entry.make_link(null, src)]<br>"
|
||||
|
||||
browse_to(user, html)
|
||||
|
||||
/datum/error_viewer/error_entry
|
||||
var/datum/error_viewer/error_source/error_source
|
||||
var/exception/exc
|
||||
var/desc = ""
|
||||
var/srcRef
|
||||
var/srcType
|
||||
var/turf/srcLoc
|
||||
var/usrRef
|
||||
var/turf/usrLoc
|
||||
var/isSkipCount
|
||||
var/usr_ref
|
||||
var/turf/usr_loc
|
||||
var/is_skip_count
|
||||
|
||||
/datum/ErrorViewer/ErrorEntry/New(var/exception/e, var/list/desclines, var/skipCount, var/datum/e_src)
|
||||
if(!istype(e))
|
||||
name = "\[[time_stamp()]] Uncaught exception: [e]"
|
||||
/datum/error_viewer/error_entry/New(exception/e, list/desclines, skip_count)
|
||||
if (!istype(e))
|
||||
name = "<b>\[[time_stamp()]]</b> Uncaught exception: <b>[html_encode(e.name)]</b>"
|
||||
return
|
||||
if(skipCount)
|
||||
name = "\[[time_stamp()]] Skipped [skipCount] runtimes in [e.file],[e.line]."
|
||||
isSkipCount = TRUE
|
||||
|
||||
if(skip_count)
|
||||
name = "\[[time_stamp()]] Skipped [skip_count] runtimes in [e.file],[e.line]."
|
||||
is_skip_count = TRUE
|
||||
return
|
||||
name = "\[[time_stamp()]] Runtime in [e.file],[e.line]: [e]"
|
||||
|
||||
name = "<b>\[[time_stamp()]]</b> Runtime in <b>[e.file]</b>, line <b>[e.line]</b>: <b>[html_encode(e.name)]</b>"
|
||||
exc = e
|
||||
if(istype(desclines))
|
||||
for(var/line in desclines)
|
||||
if (istype(desclines))
|
||||
for (var/line in desclines)
|
||||
// There's probably a better way to do this than non-breaking spaces...
|
||||
desc += " " + html_encode(line) + "<br>"
|
||||
if(istype(e_src))
|
||||
srcRef = "\ref[e_src]"
|
||||
srcType = e_src.type
|
||||
srcLoc = get_turf(e_src)
|
||||
if(usr)
|
||||
usrRef = "\ref[usr]"
|
||||
usrLoc = get_turf(usr)
|
||||
desc += "<span class='runtime_line'>[html_encode(line)]</span><br>"
|
||||
|
||||
/datum/ErrorViewer/ErrorEntry/showTo(var/user, var/datum/ErrorViewer/back_to, var/linear)
|
||||
if(!istype(back_to))
|
||||
if (usr)
|
||||
usr_ref = "[REF(usr)]"
|
||||
usr_loc = get_turf(usr)
|
||||
|
||||
/datum/error_viewer/error_entry/show_to(user, datum/error_viewer/back_to, linear)
|
||||
if (!istype(back_to))
|
||||
back_to = error_source
|
||||
var/html = buildHeader(back_to, linear)
|
||||
html += "<div class='runtime'>[html_encode(name)]<br>[desc]</div>"
|
||||
if(srcRef)
|
||||
html += "<br>src: <a href='?_src_=vars;Vars=[srcRef]'>VV</a>"
|
||||
if(ispath(srcType, /mob))
|
||||
html += " <a href='?_src_=holder;adminplayeropts=[srcRef]'>PP</a>"
|
||||
html += " <a href='?_src_=holder;adminplayerobservefollow=[srcRef]'>Follow</a>"
|
||||
if(istype(srcLoc))
|
||||
html += "<br>src.loc: <a href='?_src_=vars;Vars=\ref[srcLoc]'>VV</a>"
|
||||
html += " <a href='?_src_=holder;adminplayerobservecoodjump=1;X=[srcLoc.x];Y=[srcLoc.y];Z=[srcLoc.z]'>JMP</a>"
|
||||
if(usrRef)
|
||||
html += "<br>usr: <a href='?_src_=vars;Vars=[usrRef]'>VV</a>"
|
||||
html += " <a href='?_src_=holder;adminplayeropts=[usrRef]'>PP</a>"
|
||||
html += " <a href='?_src_=holder;adminplayerobservefollow=[usrRef]'>Follow</a>"
|
||||
if(istype(usrLoc))
|
||||
html += "<br>usr.loc: <a href='?_src_=vars;Vars=\ref[usrLoc]'>VV</a>"
|
||||
html += " <a href='?_src_=holder;adminplayerobservecoodjump=1;X=[usrLoc.x];Y=[usrLoc.y];Z=[usrLoc.z]'>JMP</a>"
|
||||
browseTo(user, html)
|
||||
|
||||
/datum/ErrorViewer/ErrorEntry/makeLink(var/linktext, var/datum/ErrorViewer/back_to, var/linear)
|
||||
if(isSkipCount)
|
||||
return html_encode(name)
|
||||
else
|
||||
return ..()
|
||||
var/html = build_header(back_to, linear)
|
||||
html += "[name]<div class='runtime'>[desc]</div>"
|
||||
if (usr_ref)
|
||||
html += "<br><b>usr</b>: <a href='?_src_=vars;[HrefToken()];Vars=[usr_ref]'>VV</a>"
|
||||
html += " <a href='?_src_=holder;[HrefToken()];adminplayeropts=[usr_ref]'>PP</a>"
|
||||
html += " <a href='?_src_=holder;[HrefToken()];adminplayerobservefollow=[usr_ref]'>Follow</a>"
|
||||
if (istype(usr_loc))
|
||||
html += "<br><b>usr.loc</b>: <a href='?_src_=vars;[HrefToken()];Vars=[REF(usr_loc)]'>VV</a>"
|
||||
html += " <a href='?_src_=holder;[HrefToken()];adminplayerobservecoodjump=1;X=[usr_loc.x];Y=[usr_loc.y];Z=[usr_loc.z]'>JMP</a>"
|
||||
|
||||
browse_to(user, html)
|
||||
|
||||
/datum/error_viewer/error_entry/make_link(linktext, datum/error_viewer/back_to, linear)
|
||||
return is_skip_count ? name : ..()
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
// Settings for the error handler and error viewer
|
||||
#undef ERROR_COOLDOWN
|
||||
#undef ERROR_LIMIT
|
||||
#undef ERROR_MAX_COOLDOWN
|
||||
#undef ERROR_SILENCE_TIME
|
||||
#undef ERROR_MSG_DELAY
|
||||
Reference in New Issue
Block a user