Skip to content

Commit

Permalink
Add API for getting last internal error message (#5772)
Browse files Browse the repository at this point in the history
* Add API for getting last internal error message

* format code (#5773)

Co-authored-by: slangbot <[email protected]>

* make message thread_local

---------

Co-authored-by: slangbot <[email protected]>
Co-authored-by: slangbot <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent ce23f07 commit d4136c9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/slang.h
Original file line number Diff line number Diff line change
Expand Up @@ -4415,6 +4415,10 @@ SLANG_API ISlangBlob* slang_getEmbeddedCoreModule();
*/
SLANG_EXTERN_C SLANG_API void slang_shutdown();

/* Return the last signaled internal error message.
*/
SLANG_EXTERN_C SLANG_API const char* slang_getLastInternalErrorMessage();

namespace slang
{
inline SlangResult createGlobalSession(slang::IGlobalSession** outGlobalSession)
Expand All @@ -4425,6 +4429,10 @@ inline void shutdown()
{
slang_shutdown();
}
inline const char* getLastInternalErrorMessage()
{
return slang_getLastInternalErrorMessage();
}
} // namespace slang

#endif // C++ helpers
Expand Down
9 changes: 9 additions & 0 deletions source/core/slang-signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Slang
{

thread_local String g_lastSignalMessage;

static const char* _getSignalTypeAsText(SignalType type)
{
switch (type)
Expand Down Expand Up @@ -54,6 +56,8 @@ String _getMessage(SignalType type, char const* message)
printf("%s\n", _getMessage(type, message).getBuffer());
}

g_lastSignalMessage = _getMessage(type, message);

#if SLANG_HAS_EXCEPTIONS
switch (type)
{
Expand All @@ -75,4 +79,9 @@ String _getMessage(SignalType type, char const* message)
#endif
}

const char* getLastSignalMessage()
{
return g_lastSignalMessage.getBuffer();
}

} // namespace Slang
2 changes: 2 additions & 0 deletions source/core/slang-signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ enum class SignalType
::Slang::handleSignal(::Slang::SignalType::AbortCompilation, msg)


const char* getLastSignalMessage();

} // namespace Slang

#endif
6 changes: 6 additions & 0 deletions source/slang/slang-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../core/slang-performance-profiler.h"
#include "../core/slang-rtti-info.h"
#include "../core/slang-shared-library.h"
#include "../core/slang-signal.h"
#include "../slang-record-replay/record/slang-global-session.h"
#include "../slang-record-replay/util/record-utility.h"
#include "slang-capability.h"
Expand Down Expand Up @@ -173,6 +174,11 @@ SLANG_API SlangResult slang_createGlobalSessionWithoutCoreModule(
return SLANG_OK;
}

SLANG_API const char* slang_getLastInternalErrorMessage()
{
return Slang::getLastSignalMessage();
}

SLANG_API void spDestroySession(SlangSession* inSession)
{
if (!inSession)
Expand Down

0 comments on commit d4136c9

Please sign in to comment.