function ErrorReporter.Report(L,e,C,N)local H,r=pcall(function()if DEBUG_REPORTER then local L=table.concat({"\082\101\099\101\105\118\101\100 \069\114\114\111\114 \058";string.format("\077\101\115\115\097\103\101 \058 \040\037\115\041 - \037\115",type(e),e);string.format("\083\116\097\099\107 \058 \040\037\115\041 - \037\115",type(C),C),string.format("\079\114\105\103\105\110 \058 \040\037\115\041 - \037\115",type(N),getFullPath(N));"\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042\042"},"\n")print(L)end local H=removePlayerNameFromStack(e)local r=removePlayerNameFromStack(C)local g=removePlayerNameFromStack(getFullPath(N))if REPORT_TO_GOOGLE_ANALYTICS then local e=L._googleAnalyticsReporter:sendEvent(GAME_VERSION,H,r)e:andThen(function()if PRINT_SUCCESSFUL_GOOGLE_ANALYTICS then print("\042\042 \083\117\099\099\101\115\115\102\117\108\108\121 \114\101\112\111\114\116\101\100 \101\114\114\111\114 \116\111 \071\111\111\103\108\101\065\110\097\108\121\116\105\099\115 \042\042","\040\083\101\116 \067\111\110\102\105\103\046\080\082\073\078\084\095\083\085\067\067\069\083\083\070\085\076\095\071\079\079\071\076\069\095\065\078\065\076\089\084\073\067\083 \116\111 \102\097\108\115\101 \116\111 \100\105\115\097\098\108\101 \116\104\105\115 \109\101\115\115\097\103\101\041")end end,function(e)warn("\069\114\114\111\114 \116\104\114\111\119\110 \119\104\105\108\101 \114\101\112\111\114\116\105\110\103 \116\111 \071\065 \058 ",e)end)end if REPORT_TO_PLAYFAB then local e=string.format("\069\114\114\111\114\115-\037\115",GAME_VERSION)local C={error=H;stack=H,origin=g}L._playFabReporter:fireEvent(e,C)if PRINT_SUCCESSFUL_PLAYFAB then print("\042\042 \083\117\099\099\101\115\115\102\117\108\108\121 \114\101\112\111\114\116\101\100 \101\114\114\111\114 \116\111 \080\108\097\121\070\097\098 \042\042","\040\083\101\116 \067\111\110\102\105\103\046\080\082\073\078\084\095\083\085\067\067\069\083\083\070\085\076\095\080\076\065\089\070\065\066 \116\111 \102\097\108\115\101 \116\111 \100\105\115\097\098\108\101 \116\104\105\115 \109\101\115\115\097\103\101\041")end end end)if not H then local L=table.concat({"\069\114\114\111\114 \082\101\112\111\114\116\101\114 \116\104\114\101\119 \097\110 \101\114\114\111\114 \058",tostring(r);"\087\104\105\108\101 \114\101\112\111\114\116\105\110\103\046\046\046",string.format("\077\101\115\115\097\103\101 \058 \040\037\115\041 - \037\115",type(e),e),string.format("\083\116\097\099\107 \058 \040\037\115\041 - \037\115",type(C),C),string.format("\079\114\105\103\105\110 \058 \040\037\115\041 - \037\115",type(N),tostring(N))},"\n")warn(L)end end return ErrorReporter
-- message : (string) the text of error thrown
-- stack : (string) the debug.traceback() of the where the error originated
-- origin : (datatype) the container where the error came from
function ErrorReporter:Report(message, stack, origin)
	-- make sure that there isn't a circular loop of errors
	local success, result = pcall(function()
		if DEBUG_REPORTER then
			local debugMsg = table.concat({
				"Received Error :",
				string.format("Message : (%s) - %s", type(message), message),
				string.format("Stack : (%s) - %s", type(stack), stack),
				string.format("Origin : (%s) - %s", type(origin), getFullPath(origin)),
				"***************************",
			}, "\n")
			print(debugMsg)
		end

		-- format the message and stack
		local strMessage = removePlayerNameFromStack(message)
		local strStack = removePlayerNameFromStack(stack)
		local strOrigin = removePlayerNameFromStack(getFullPath(origin))

		-- report the error to all reporters
		if REPORT_TO_GOOGLE_ANALYTICS then
			local p = self._googleAnalyticsReporter:sendEvent(GAME_VERSION, strMessage, strStack)
			p:andThen(function()
				if PRINT_SUCCESSFUL_GOOGLE_ANALYTICS then
					print(
						"** Successfully reported error to GoogleAnalytics **",
						"(Set Config.PRINT_SUCCESSFUL_GOOGLE_ANALYTICS to false to disable this message)"
					)
				end
			end, function(err)
				warn("Error thrown while reporting to GA : ", err)
			end)
		end

		if REPORT_TO_PLAYFAB then
			local category = string.format("Errors-%s", GAME_VERSION)
			local value = {
				error = strMessage,
				stack = strMessage,
				origin = strOrigin,
			}
			self._playFabReporter:fireEvent(category, value)

			-- PlayFab will not work while testing in Studio. It will give you an error saying :
			-- `AnalyticsService can only be executed by game server.`
			-- This means that you have to be playing a published game to get any real data.
			-- But as far as this script cares, you successfully sent data to PlayFab.
			if PRINT_SUCCESSFUL_PLAYFAB then
				print(
					"** Successfully reported error to PlayFab **",
					"(Set Config.PRINT_SUCCESSFUL_PLAYFAB to false to disable this message)"
				)
			end
		end
	end)

	if not success then
		local warning = table.concat({
			"Error Reporter threw an error :",
			tostring(result),
			"While reporting...",
			string.format("Message : (%s) - %s", type(message), message),
			string.format("Stack : (%s) - %s", type(stack), stack),
			string.format("Origin : (%s) - %s", type(origin), tostring(origin)),
		}, "\n")
		warn(warning)
	end
end

return ErrorReporter
