Complete Error Tracking Example
A full integration showing error tracking across different game scenarios.
Game Manager Setup
# game_manager.gd
extends Node
func _ready():
print("Error tracking ready")
func _on_connection_failed(error_code: int):
ShardSDK.monitor.report_error(
"Failed to connect to server: error code " + str(error_code)
)
func _on_save_corrupted(file_path: String):
ShardSDK.monitor.report_error(
"Save file corrupted: " + file_path
)Tracking Network Errors
# network_manager.gd
extends Node
func _on_http_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray):
if result != HTTPRequest.RESULT_SUCCESS:
ShardSDK.monitor.report_error(
"HTTP request failed with result: " + str(result)
)
elif response_code >= 400:
ShardSDK.monitor.report_error(
"HTTP error response: " + str(response_code)
)
func _on_websocket_error(error_message: String):
ShardSDK.monitor.report_error("WebSocket error: " + error_message)Tracking Exceptions with Stack Traces
# exception_handler.gd
extends Node
func safe_call(callable: Callable) -> Variant:
# Note: GDScript doesn't have try/catch, but you can capture errors
# through push_error and custom error handling
var result = callable.call()
return result
func report_with_stack(message: String):
var stack = get_stack()
var stack_str = ""
for frame in stack:
stack_str += "%s:%d in %s\n" % [frame.source, frame.line, frame.function]
ShardSDK.monitor.report_error(message, stack_str)Common Error Scenarios
Save/Load Errors
func load_save_file(path: String) -> Dictionary:
if not FileAccess.file_exists(path):
ShardSDK.monitor.report_error("Save file not found: " + path)
return {}
var file = FileAccess.open(path, FileAccess.READ)
if file == null:
ShardSDK.monitor.report_error(
"Failed to open save file: " + str(FileAccess.get_open_error())
)
return {}
var json = JSON.new()
var parse_result = json.parse(file.get_as_text())
if parse_result != OK:
ShardSDK.monitor.report_error(
"Failed to parse save file: " + json.get_error_message()
)
return {}
return json.dataResource Loading Errors
func load_texture(path: String) -> Texture2D:
var texture = load(path) as Texture2D
if texture == null:
ShardSDK.monitor.report_error("Failed to load texture: " + path)
return textureAPI Quick Reference
# Report error
ShardSDK.monitor.report_error(message)
ShardSDK.monitor.report_error(message, stack_trace)