Is there a way make an error screen for any error ocurred?

So, doing my usual tomfoolery for my game, I stumbled with this error message: “Texture key already in use: pressenter_text” and thought to myself…

Is there any way to detect this errors to launch an error screen? So that’s what I am trying to figure out, is there any way to trigger a scene when the console or the game detects an error at any time?

You can use a window error event handler (and try catch in that, to avoid an error spiral).

However, Texture key already in use … is not a true runtime error but a message from Phaser using console.error(), so it wouldn’t apply.

So how can I detect the errors in Phaser too?

You would still get real errors from Phaser or your own code using that method, just not console.error() messages.

And for that particular texture problem, you can check this.textures.exists(key) first.

I’ll see if that works, thanks! (also, the error was a multiple call for starting a scene, I fixed it adding a check for detecting if the player is or isn’t on a specific state, if it isn’t, it will enable itself, making it so it doesn’t repeat the this.scene.launch)

When I was building my game for iOS and Android, I found that it was difficult to troubleshoot issues in my builds, so I put together the following code to alert errors to the screen. As samme mentioned though, the “key exists” thing is warning, not an error so it won’t show that. My code mainly shows game breaking issues. You can replace the alert with a scene launcher if you really want to.

window.onerror = function (message, source, lineno, colno, error) {
	const errorMsg = `Error: ${message}\nSource: ${source}\nLine: ${lineno}, Column: ${colno}\nStack: ${
		error?.stack || "N/A"
	}`;
	alert(errorMsg);
	return true;
};

window.addEventListener(
	"error",
	function (e) {
		const errorMsg = `Resource Error: ${e.message || e.type}\nTarget: ${
			e.target?.src || e.filename || "N/A"
		}`;
		alert(errorMsg);
	},
	true
); // Use capture to catch deeper issues

window.addEventListener("unhandledrejection", function (event) {
	const errorMsg = `Unhandled Promise Rejection: ${
		event.reason?.message || event.reason || "Unknown"
	}`;
	alert(errorMsg);
});