Skip to content

Commit d4136c9

Browse files
Add API for getting last internal error message (#5772)
* Add API for getting last internal error message * format code (#5773) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * make message thread_local --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
1 parent ce23f07 commit d4136c9

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

include/slang.h

+8
Original file line numberDiff line numberDiff line change
@@ -4415,6 +4415,10 @@ SLANG_API ISlangBlob* slang_getEmbeddedCoreModule();
44154415
*/
44164416
SLANG_EXTERN_C SLANG_API void slang_shutdown();
44174417

4418+
/* Return the last signaled internal error message.
4419+
*/
4420+
SLANG_EXTERN_C SLANG_API const char* slang_getLastInternalErrorMessage();
4421+
44184422
namespace slang
44194423
{
44204424
inline SlangResult createGlobalSession(slang::IGlobalSession** outGlobalSession)
@@ -4425,6 +4429,10 @@ inline void shutdown()
44254429
{
44264430
slang_shutdown();
44274431
}
4432+
inline const char* getLastInternalErrorMessage()
4433+
{
4434+
return slang_getLastInternalErrorMessage();
4435+
}
44284436
} // namespace slang
44294437

44304438
#endif // C++ helpers

source/core/slang-signal.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Slang
77
{
88

9+
thread_local String g_lastSignalMessage;
10+
911
static const char* _getSignalTypeAsText(SignalType type)
1012
{
1113
switch (type)
@@ -54,6 +56,8 @@ String _getMessage(SignalType type, char const* message)
5456
printf("%s\n", _getMessage(type, message).getBuffer());
5557
}
5658

59+
g_lastSignalMessage = _getMessage(type, message);
60+
5761
#if SLANG_HAS_EXCEPTIONS
5862
switch (type)
5963
{
@@ -75,4 +79,9 @@ String _getMessage(SignalType type, char const* message)
7579
#endif
7680
}
7781

82+
const char* getLastSignalMessage()
83+
{
84+
return g_lastSignalMessage.getBuffer();
85+
}
86+
7887
} // namespace Slang

source/core/slang-signal.h

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ enum class SignalType
3535
::Slang::handleSignal(::Slang::SignalType::AbortCompilation, msg)
3636

3737

38+
const char* getLastSignalMessage();
39+
3840
} // namespace Slang
3941

4042
#endif

source/slang/slang-api.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../core/slang-performance-profiler.h"
44
#include "../core/slang-rtti-info.h"
55
#include "../core/slang-shared-library.h"
6+
#include "../core/slang-signal.h"
67
#include "../slang-record-replay/record/slang-global-session.h"
78
#include "../slang-record-replay/util/record-utility.h"
89
#include "slang-capability.h"
@@ -173,6 +174,11 @@ SLANG_API SlangResult slang_createGlobalSessionWithoutCoreModule(
173174
return SLANG_OK;
174175
}
175176

177+
SLANG_API const char* slang_getLastInternalErrorMessage()
178+
{
179+
return Slang::getLastSignalMessage();
180+
}
181+
176182
SLANG_API void spDestroySession(SlangSession* inSession)
177183
{
178184
if (!inSession)

0 commit comments

Comments
 (0)