Repository: godot
Issue: Command line export doesn't exit if there is a build error
Labels: bug,topic:export

### Tested versions

Reproducible in 
- v4.3.dev6.mono.official [89850d553]
  - hangs at the very end
- v4.3.beta1.mono.official [a4f2ea91a]
  - hangs after "ERROR: Attempting to parent and popup a dialog that already has a parent."


### System information

Godot v4.3.dev6.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 6GB (NVIDIA; 31.0.15.5212) - Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 Threads)

### Issue description

If I try to export the project from command line but there is build error, either GDScript error or C# error, Godot executable doesn't exit. I need to press Ctrl-C to exit.

A build error seems to cause this problem every time. But I also noticed that sometimes even working build doesn't exit cleanly if I ran the export command from Window's bat-file. However, I don't know to reprocude that. 

I also wonder, if it would be better to instantly quit the exporting process, if the build fails. Now the process continues with the savepack.

This is a somewhat shortened and anonymized output:
```
λ "C:\godot\Godot_v4.3-dev6_mono_win64\Godot_v4.3-dev6_mono_win64_console.exe" --verbose --headless --no-window --export-release "Windows Desktop"
Godot Engine v4.3.dev6.mono.official.89850d553 - https://godotengine.org
TextServer: Added interface "Dummy"
TextServer: Added interface "ICU / HarfBuzz / Graphite (Built-in)"
Using "default" pen tablet driver...

TextServer: Primary interface set to: "ICU / HarfBuzz / Graphite (Built-in)".
.NET: Initializing module...
Found hostfxr: C:\Program Files\dotnet\host/fxr/8.0.4/hostfxr.dll
.NET: hostfxr initialized
.NET: GodotPlugins initialized
CORE API HASH: 3400182566
EDITOR API HASH: 130872444
EditorSettings: Load OK!
EditorTheme: Generating new theme for the config '66886095'.
EditorTheme: Generating new icons.
EditorTheme: Generating new fonts.
EditorTheme: Generating new styles.
Found .NET Sdk version '8.0.204': C:\Program Files\dotnet\sdk\8.0.204
Loaded system CA certificates
Failed to bind socket. Error: 3
Failed to bind socket. Error: 3
EditorSettings: Save OK!
update_scene_groups: begin: Update Scene Groups steps: 16
        update_scene_groups: step 0: Updating Scene Groups...
        update_scene_groups: step 1: Updating Scene Groups...
        update_scene_groups: step 2: Updating Scene Groups...
        update_scene_groups: step 3: Updating Scene Groups...
        update_scene_groups: step 4: Updating Scene Groups...
        update_scene_groups: step 5: Updating Scene Groups...
        update_scene_groups: step 6: Updating Scene Groups...
        update_scene_groups: step 7: Updating Scene Groups...
        update_scene_groups: step 8: Updating Scene Groups...
        update_scene_groups: step 9: Updating Scene Groups...
        update_scene_groups: step 10: Updating Scene Groups...
        update_scene_groups: step 11: Updating Scene Groups...
        update_scene_groups: step 12: Updating Scene Groups...
        update_scene_groups: step 13: Updating Scene Groups...
        update_scene_groups: step 14: Updating Scene Groups...
        update_scene_groups: step 15: Updating Scene Groups...
update_scene_groups: end
dotnet_publish_project: begin: Publishing .NET project... steps: 1
        dotnet_publish_project: step 0: Running dotnet publish
Running:  "C:\Program Files\dotnet\dotnet.EXE" publish C:/godot/foo/bar.csproj -c ExportRelease -r win-x64 --self-contained true -v normal -l:GodotTools.BuildLogger.GodotBuildLogger,... ...
dotnet publish exited with code: 1. Log file: ...
dotnet_publish_project: end
ERROR: Failed to export project: Failed to build project.
   at: void GodotTools.Export.ExportPlugin._ExportBegin(System.String[], bool, string, uint) (/root/godot/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs:123)
System.InvalidOperationException: Failed to build project.
   at GodotTools.Export.ExportPlugin._ExportBeginImpl(String[] features, Boolean isDebug, String path, Int64 flags) in /root/godot/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs:line 255
   at GodotTools.Export.ExportPlugin._ExportBegin(String[] features, Boolean isDebug, String path, UInt32 flags) in /root/godot/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs:line 123
savepack: begin: Packing steps: 102
...
savepack: end
ERROR: Attempting to parent and popup a dialog that already has a parent.
   at: (scene/main/window.cpp:1838)                          <--- !!! 4.3 beta1 hangs after this line !!!
EditorSettings: Save OK!
Unloading: Disposing tracked instances...
Unloading: Finished disposing tracked instances.
XR: Clearing primary interface
XR: Removed interface "Native mobile"
XR: Removed interface "OpenXR"
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: cleanup (core/object/object.cpp:2314)
Leaked instance: Image:9223373671391885761 - Resource path:
Leaked instance: Image:9223373672683731395 - Resource path:
Hint: Leaked instances typically happen when nodes are removed from the scene tree (with `remove_child()`) but not freed (with `free()` or `queue_free()`).
Orphan StringName: _setup_local_to_scene (static: 0, total: 2)
Orphan StringName: EditorFileDialog (static: 1, total: 7)
Orphan StringName: AudioStream (static: 0, total: 1)
Orphan StringName: ItemList (static: 1, total: 9)
Orphan StringName: TabBar (static: 1, total: 9)
Orphan StringName: FileDialog (static: 6, total: 12)
Orphan StringName: AudioStreamRandomizer (static: 1, total: 5)
Orphan StringName: export_presets_runnable_updated (static: 0, total: 1)
Orphan StringName: OptionButton (static: 2, total: 12)
Orphan StringName: Node (static: 12, total: 13)
Orphan StringName: export_presets_updated (static: 0, total: 1)
Orphan StringName: Texture2D (static: 0, total: 5)
Orphan StringName: PopupMenu (static: 1, total: 15)
StringName: 13 unclaimed string names at exit.
^C                                                   <--- !!! pressing Ctrl-C here !!!
```

This is what Windows task manager displays while building:
![kuva](https://github.com/godotengine/godot/assets/49998025/f20660f2-d9d4-4868-9c6d-5a5707a74af0)
and finally after the error message:
![kuva](https://github.com/godotengine/godot/assets/49998025/b63694c2-3874-497e-8ed8-df01bc04cd2d)
After pressing Ctrl-C `.NET Host` and `Godot Engine (Console)` disappear from Task manager.


### Steps to reproduce

1. Add some build breaking error to the project code.
2. Run `"Godot_v4.3-beta1_mono_win64\Godot_v4.3-beta1_mono_win64_console.exe" --verbose --headless --no-window --export-release "Windows Desktop"`

### Minimal reproduction project (MRP)

N/A