|
| 1 | +package cm |
| 2 | + |
| 3 | +import "unsafe" |
| 4 | + |
| 5 | +// ErrorContext represents the Component Model [error-context] type, |
| 6 | +// an immutable, non-deterministic, host-defined value meant to aid in debugging. |
| 7 | +// |
| 8 | +// [error-context]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-context-type |
| 9 | +type ErrorContext struct { |
| 10 | + _ HostLayout |
| 11 | + errorContext |
| 12 | +} |
| 13 | + |
| 14 | +type errorContext uint32 |
| 15 | + |
| 16 | +// Error implements the [error] interface. It returns the debug message associated with err. |
| 17 | +func (err errorContext) Error() string { |
| 18 | + return err.DebugMessage() |
| 19 | +} |
| 20 | + |
| 21 | +// String implements [fmt.Stringer]. |
| 22 | +func (err errorContext) String() string { |
| 23 | + return err.DebugMessage() |
| 24 | +} |
| 25 | + |
| 26 | +// DebugMessage represents the Canonical ABI [error-context.debug-message] function. |
| 27 | +// |
| 28 | +// [error-context.debug-message]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-contextdebug-message |
| 29 | +func (err errorContext) DebugMessage() string { |
| 30 | + var s string |
| 31 | + errorContextDebugMessage(err, unsafe.Pointer(&s)) |
| 32 | + return s |
| 33 | +} |
| 34 | + |
| 35 | +//go:wasmimport canon error-context.debug-message |
| 36 | +//go:noescape |
| 37 | +func errorContextDebugMessage(err errorContext, msg unsafe.Pointer) |
| 38 | + |
| 39 | +// Drop represents the Canonical ABI [error-context.drop] function. |
| 40 | +// |
| 41 | +// [error-context.drop]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-contextdrop |
| 42 | +func (err errorContext) Drop() { |
| 43 | + errorContextDrop(err) |
| 44 | +} |
| 45 | + |
| 46 | +//go:wasmimport canon error-context.drop |
| 47 | +//go:noescape |
| 48 | +func errorContextDrop(err errorContext) |
0 commit comments