I was using Debian 12 today, and I had the terminal window open installing some stuff on my machine. Once I closed the terminal, I got the error " Failed to execute default terminal emulator".
I did not change anything on system settings or preferences of the terminal, so I wasn't sure what was causing this issue.
The error seem to happen only when you close the terminal window, and not when you launch it. So this tells me that the error is being caused by the signal (SIGHUP) that is sent when you terminate a process on linux.
So I tried launching default terminal from another terminal session, and error seemed to be gone, then I went and launched terminal again from the Applications Menu, and closed it, and I got the same error again.
So, the error seems to happen only when you close the terminal that you launched it from the Applications Menu, and not when you launch x-terminal-emulator
from another shell session.
After lots of testing, I was able to identify the cause of this error.
In this tutorial, you will learn how to fix the error "Failed to execute default terminal emulator" on Debian 12.
Step 1 - Set Default terminal emulator
Since the error is related to the default terminal emulator, you need check that the x-terminal-emulator is set as the default terminal on your system.
You can check this from the "Default Applications" window.
Launch Applications Menu, next go to Settings and then go to "Default Applications"

And you will see Default Applications window. Now, simply click to "Utilities" tab

Once you are in the Utilities tab, you need to set x-terminal-emulator as default emulator on your system. To do this, simply click to the Drop down arrow, and select " Debian X Terminal Emulator"

Close the window when done.
To change the default terminal using terminal, you can do so by running the command below
sudo update-alternatives --config x-terminal-emulator
Next, you need to choose the terminal that you want to make as default, type your selection and press enter.
For example, I'm setting xfce terminal as the default terminal on my machine

Step 2 - Reset Terminal Preferences
Resetting settings it's necessary in cases like this because if there's a setting that is causing this issue then resetting them would fix it.
To reset the settings of your terminal, run the command below
dconf reset -f /org/gnome/terminal/legacy
In my case, this error was being caused by the theme setting, the setting that lets you select a theme variant for your terminal. Resetting settings would have fixed this issue for me too. However, I did not want to only fix it, I wanted more to know what was causing it, and I was able to identify the cause of error after a lot of testing.

My system was using the default light theme, and the theme variant for the terminal was set to Dark. So I changed it back to Light theme variant, and the error was gone.

Then I tried again setting it to Dark, because I wanted to verify and double check that this setting was causing this error, and once I set it to Dark mode again, I got the same error again.

Step 3 - Set gnome or xfce as default terminal
Later I found out that changing the default terminal to Gnome terminal or xfce-terminal also fixes this issue. To set gnome-terminal or xfce terminal as your default terminal emulator on Debian 12, you can do so by running the command below
sudo update-alternatives --config x-terminal-emulator
And choose the default emulator

Press enter once you have entered your selection.
Conclusion
In this tutorial, you learned how to fix "Failed to execute default terminal emulator" error on Debian 12.
The cause of this error was that the terminal was using the dark theme variant while system was using the light theme. We also explained that changing the default emulator to gnome or xfce terminal can also fix this issue even when the theme variant is different on the system or terminal.