Skip to content

Commit

Permalink
Use task for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Mar 5, 2025
1 parent 9bd806f commit 44eb5db
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/engine/Entity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,24 @@ module EntityModule
try
Base.invokelatest(JulGame.update, script, deltaTime)
catch e
Threads.@spawn begin
err_str = string(e)
formatted_err = format_method_error(err_str) # Format MethodError
truncated_err = length(formatted_err) > 1500 ? formatted_err[1:1500] * "..." : formatted_err

@error "Error occurred" exception=truncated_err
Base.show_backtrace(stderr, catch_backtrace())
task = @task begin
print_error(e)
end
schedule(task)
yield()
end
end
end

function print_error(e)
err_str = string(e)
formatted_err = format_method_error(err_str) # Format MethodError
truncated_err = length(formatted_err) > 1500 ? formatted_err[1:1500] * "..." : formatted_err

@error "Error occurred" exception=truncated_err
Base.show_backtrace(stderr, catch_backtrace())
end

function format_method_error(error_msg::String)
# Match "MethodError(FUNCTION_NAME, (ARGUMENTS))"
if occursin(r"MethodError\((.+?), \((.+)\)\)", error_msg)
Expand Down

0 comments on commit 44eb5db

Please sign in to comment.