Class PanamaErrorMapper
java.lang.Object
ai.tegmentum.wasmtime4j.panama.util.PanamaErrorMapper
Utility class for mapping native error codes to appropriate Java exceptions in Panama.
This class translates native error codes (as defined by WasmErrorCode) into the
appropriate exception types from the public API exception hierarchy. It ensures that Panama
callers produce meaningful, categorized exceptions instead of raw error code integers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetErrorDescription(int errorCode) Returns a human-readable description for a native error code.static ai.tegmentum.wasmtime4j.exception.WasmExceptionmapNativeError(int errorCode) Maps a native error code to an appropriate Java exception with no additional context.static ai.tegmentum.wasmtime4j.exception.WasmExceptionmapNativeError(int errorCode, String context) Maps a native error code and context message to an appropriate Java exception.static StringRetrieves the last error message from the native library and clears it.static voidwriteErrorMessage(MemorySegment errorMsgPtr, int errorMsgLen, String message) Writes an error message to a native error buffer.
-
Method Details
-
retrieveNativeErrorMessage
Retrieves the last error message from the native library and clears it.- Returns:
- the error message, or null if no error
-
mapNativeError
public static ai.tegmentum.wasmtime4j.exception.WasmException mapNativeError(int errorCode, String context) Maps a native error code and context message to an appropriate Java exception.Delegates to the shared
ErrorMapperfor consistent error categorization across both JNI and Panama implementations.- Parameters:
errorCode- the native error codecontext- a description of the operation that failed- Returns:
- the appropriate Java exception
-
mapNativeError
public static ai.tegmentum.wasmtime4j.exception.WasmException mapNativeError(int errorCode) Maps a native error code to an appropriate Java exception with no additional context.- Parameters:
errorCode- the native error code- Returns:
- the appropriate Java exception
-
writeErrorMessage
Writes an error message to a native error buffer.Truncates the message if it exceeds the buffer size, and always null-terminates.
- Parameters:
errorMsgPtr- pointer to the error message buffererrorMsgLen- size of the error message buffermessage- the error message to write
-
getErrorDescription
Returns a human-readable description for a native error code.- Parameters:
errorCode- the native error code- Returns:
- the error description, or a default message for unknown codes
-