## Records engine and script errors so the runner can fail the test that caused them. ## Godot may call a Logger from any thread, so all state is guarded by a mutex, and ## nothing here prints (printing from a logger callback would recurse). class_name TestLogger extends Logger var _mutex: Mutex = Mutex.new() var _errors: Array[String] = [] func _log_error( function: String, file: String, line: int, code: String, rationale: String, _editor_notify: bool, error_type: int, _script_backtrace: Array[ScriptBacktrace], ) -> void: if error_type == Logger.ERROR_TYPE_WARNING: return var what: String = rationale if not rationale.is_empty() else code var entry: String = "%s (at %s:%d in %s)" % [what, file, line, function] _mutex.lock() _errors.append(entry) _mutex.unlock() ## Returns every error recorded since the last call, and clears the record. func take_errors() -> Array[String]: _mutex.lock() var taken: Array[String] = _errors _errors = [] _mutex.unlock() return taken