mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
This PR implements widely accepted Rust programming practices for dealing with panics across ABI (programming language) boundaries. - Add panic_guard.rs to wrap FFI calls and prevent panic across FFI/ABI boundary (undefined behavior). - Capture per-thread backtraces via a temporary panic hook - After a panic, subsequent invocations are poisoned. - Integrate with_unwind_guard across the engine, schema registry, and target registry exportis Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
25 lines
738 B
C#
25 lines
738 B
C#
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
using System;
|
|
|
|
#nullable enable
|
|
|
|
namespace Regorus.Internal
|
|
{
|
|
internal static class StatusExtensions
|
|
{
|
|
internal static Exception CreateException(this RegorusStatus status, string? message)
|
|
{
|
|
var details = string.IsNullOrWhiteSpace(message) ? "Regorus call failed." : message;
|
|
|
|
return status switch
|
|
{
|
|
RegorusStatus.Panic => new InvalidOperationException($"Regorus engine panicked: {details}"),
|
|
RegorusStatus.Poisoned => new InvalidOperationException($"Regorus engine is poisoned: {details}"),
|
|
_ => new Exception(details),
|
|
};
|
|
}
|
|
}
|
|
}
|