Uncaught exception when trying to generate a project using Ninja Multi-Config

Ninja Multi-Config crashes with uncaught exception when trying to add a subfolder where its CMakeLists.txt defines different configuration types than the main project CMakeLists.txt does.

The issue is reproducible with the simplified example below. CMake 3.29.5 is used.
I guess the generator should not behave this way?

Backtrace

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x000000019a51ea60 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x000000019a556c20 libsystem_pthread.dylib`pthread_kill + 288
    frame #2: 0x000000019a463a30 libsystem_c.dylib`abort + 180
    frame #3: 0x000000019a50dd08 libc++abi.dylib`abort_message + 132
    frame #4: 0x000000019a4fdfa4 libc++abi.dylib`demangling_terminate_handler() + 320
    frame #5: 0x000000019a19c1e0 libobjc.A.dylib`_objc_terminate() + 160
    frame #6: 0x000000019a50d0cc libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x000000019a510348 libc++abi.dylib`__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 88
    frame #8: 0x000000019a51028c libc++abi.dylib`__cxa_throw + 308
    frame #9: 0x000000010001ead0 cmake`std::__1::__throw_out_of_range[abi:ue170006](__msg="map::at:  key not found") at stdexcept:273:5
    frame #10: 0x0000000100c1ac7c cmake`std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::unique_ptr<cmGeneratedFileStream, std::__1::default_delete<cmGeneratedFileStream>>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const, std::__1::unique_ptr<cmGeneratedFileStream, std::__1::default_delete<cmGeneratedFileStream>>>>>::at(this=0x000000015901e8e8 size=2, __k="SomethingElse") const at map:1759:9
    frame #11: 0x0000000100c17b4c cmake`cmGlobalNinjaMultiGenerator::GetImplFileStream(this=0x000000015901e200, config="SomethingElse") const at cmGlobalNinjaGenerator.h:708:34
    frame #12: 0x0000000100c3336c cmake`cmLocalNinjaGenerator::GetImplFileStream(this=0x0000000139a07750, config="SomethingElse") const at cmLocalNinjaGenerator.cxx:226:44
    frame #13: 0x0000000100c32858 cmake`cmLocalNinjaGenerator::Generate(this=0x0000000139a07750) at cmLocalNinjaGenerator.cxx:75:44
    frame #14: 0x00000001005da398 cmake`cmGlobalGenerator::Generate(this=0x000000015901e200) at cmGlobalGenerator.cxx:1694:31
    frame #15: 0x0000000100c03c74 cmake`cmGlobalNinjaGenerator::Generate(this=0x000000015901e200) at cmGlobalNinjaGenerator.cxx:648:28
    frame #16: 0x000000010093ff2c cmake`cmake::Generate(this=0x000000016fdfd560) at cmake.cxx:2896:26
    frame #17: 0x000000010093e56c cmake`cmake::Run(this=0x000000016fdfd560, args=size=5, noconfigure=false) at cmake.cxx:2871:15
    frame #18: 0x0000000100008418 cmake`(anonymous namespace)::do_cmake(ac=5, av=0x000060000201b120) at cmakemain.cxx:366:16
    frame #19: 0x000000010000497c cmake`main(ac=5, av=0x000060000201b120) at cmakemain.cxx:1075:13
    frame #20: 0x000000019a1ce0e0 dyld`start + 2360

Files

./CMakeLists.txt
./hello.cpp
./subproject/CMakeLists.txt

./CMakeLists.txt

cmake_minimum_required(VERSION 3.29)
project("hello" LANGUAGES CXX)
set(CMAKE_CONFIGURATION_TYPES Debug Release)
add_executable("hello" hello.cpp)
add_subdirectory(subproject)

./hello.cpp

#include <iostream>
int main() {
std::cout << "Hello, World!";
return 0;
}

./subproject/CMakeLists.txt

## this fails
set(CMAKE_CONFIGURATION_TYPES Debug Release SomethingElse)
## this works
#set(CMAKE_CONFIGURATION_TYPES Debug Release)

Behavior with Ninja Multi-Config

$ cmake . -B buildninjamulti -G"Ninja Multi-Config"
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.2s)
libc++abi: terminating due to uncaught exception of type std::out_of_range: map::at: key not found
[1] 38680 abort cmake . -B buildninjamulti -G"Ninja Multi-Config"

Behavior with Xcode

For comparison

$ cmake . -B buildxcode -GXcode
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (2.4s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/example/buildxcode

I doubt it’s supported to try to change the value of CMAKE_CONFIGURATION_TYPES in different parts of the project, but CMake at least shouldn’t crash. Please open a bug report for this in the issue tracker: https://gitlab.kitware.com/cmake/cmake/-/issues/new