Skip to content

Commit 06c30c0

Browse files
shschaeferStuart Schaefer
and
Stuart Schaefer
authored
Simple proposal to extend error handling. (#64)
* Simple proposal to extend error handling. * Changing error to code. --------- Co-authored-by: Stuart Schaefer <[email protected]>
1 parent ac355f3 commit 06c30c0

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

ml.md

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,51 @@ memory--e.g., using row-major ordering--and could perhaps be improved.</p>
9090
<p>TODO: create function-specific errors (https://github.com/WebAssembly/wasi-nn/issues/42)</p>
9191
<hr />
9292
<h3>Types</h3>
93-
<h4><a name="error"><code>enum error</code></a></h4>
93+
<h4><a name="error_code"><code>enum error-code</code></a></h4>
9494
<h5>Enum Cases</h5>
9595
<ul>
96-
<li><a name="error.invalid_argument"><code>invalid-argument</code></a></li>
97-
<li><a name="error.invalid_encoding"><code>invalid-encoding</code></a></li>
98-
<li><a name="error.busy"><code>busy</code></a></li>
99-
<li><a name="error.runtime_error"><code>runtime-error</code></a></li>
100-
<li><a name="error.unsupported_operation"><code>unsupported-operation</code></a></li>
101-
<li><a name="error.too_large"><code>too-large</code></a></li>
102-
<li><a name="error.not_found"><code>not-found</code></a></li>
96+
<li><a name="error_code.invalid_argument"><code>invalid-argument</code></a></li>
97+
<li><a name="error_code.invalid_encoding"><code>invalid-encoding</code></a></li>
98+
<li><a name="error_code.timeout"><code>timeout</code></a></li>
99+
<li><a name="error_code.runtime_error"><code>runtime-error</code></a></li>
100+
<li><a name="error_code.unsupported_operation"><code>unsupported-operation</code></a></li>
101+
<li><a name="error_code.too_large"><code>too-large</code></a></li>
102+
<li><a name="error_code.not_found"><code>not-found</code></a></li>
103+
<li><a name="error_code.security"><code>security</code></a></li>
104+
<li><a name="error_code.unknown"><code>unknown</code></a></li>
105+
</ul>
106+
<h4><a name="error"><code>resource error</code></a></h4>
107+
<hr />
108+
<h3>Functions</h3>
109+
<h4><a name="constructor_error"><code>[constructor]error: func</code></a></h4>
110+
<h5>Params</h5>
111+
<ul>
112+
<li><a name="constructor_error.code"><code>code</code></a>: <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a></li>
113+
<li><a name="constructor_error.data"><code>data</code></a>: <code>string</code></li>
114+
</ul>
115+
<h5>Return values</h5>
116+
<ul>
117+
<li><a name="constructor_error.0"></a> own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
118+
</ul>
119+
<h4><a name="method_error.code"><code>[method]error.code: func</code></a></h4>
120+
<p>Return the error code.</p>
121+
<h5>Params</h5>
122+
<ul>
123+
<li><a name="method_error.code.self"><code>self</code></a>: borrow&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
124+
</ul>
125+
<h5>Return values</h5>
126+
<ul>
127+
<li><a name="method_error.code.0"></a> <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a></li>
128+
</ul>
129+
<h4><a name="method_error.data"><code>[method]error.data: func</code></a></h4>
130+
<p>Errors can propagated with backend specific status through a string value.</p>
131+
<h5>Params</h5>
132+
<ul>
133+
<li><a name="method_error.data.self"><code>self</code></a>: borrow&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
134+
</ul>
135+
<h5>Return values</h5>
136+
<ul>
137+
<li><a name="method_error.data.0"></a> <code>string</code></li>
103138
</ul>
104139
<h2><a name="wasi:nn_inference">Import interface wasi:nn/inference</a></h2>
105140
<p>An inference &quot;session&quot; is encapsulated by a <a href="#graph_execution_context"><code>graph-execution-context</code></a>. This structure binds a
@@ -128,7 +163,7 @@ memory--e.g., using row-major ordering--and could perhaps be improved.</p>
128163
</ul>
129164
<h5>Return values</h5>
130165
<ul>
131-
<li><a name="method_graph_execution_context.set_input.0"></a> result&lt;_, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
166+
<li><a name="method_graph_execution_context.set_input.0"></a> result&lt;_, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
132167
</ul>
133168
<h4><a name="method_graph_execution_context.compute"><code>[method]graph-execution-context.compute: func</code></a></h4>
134169
<p>Compute the inference on the given inputs.</p>
@@ -141,7 +176,7 @@ https://github.com/WebAssembly/wasi-nn/issues/43.</p>
141176
</ul>
142177
<h5>Return values</h5>
143178
<ul>
144-
<li><a name="method_graph_execution_context.compute.0"></a> result&lt;_, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
179+
<li><a name="method_graph_execution_context.compute.0"></a> result&lt;_, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
145180
</ul>
146181
<h4><a name="method_graph_execution_context.get_output"><code>[method]graph-execution-context.get-output: func</code></a></h4>
147182
<p>Extract the outputs after inference.</p>
@@ -152,7 +187,7 @@ https://github.com/WebAssembly/wasi-nn/issues/43.</p>
152187
</ul>
153188
<h5>Return values</h5>
154189
<ul>
155-
<li><a name="method_graph_execution_context.get_output.0"></a> result&lt;own&lt;<a href="#tensor"><a href="#tensor"><code>tensor</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
190+
<li><a name="method_graph_execution_context.get_output.0"></a> result&lt;own&lt;<a href="#tensor"><a href="#tensor"><code>tensor</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
156191
</ul>
157192
<h2><a name="wasi:nn_graph">Import interface wasi:nn/graph</a></h2>
158193
<p>A <a href="#graph"><code>graph</code></a> is a loaded instance of a specific ML model (e.g., MobileNet) for a specific ML
@@ -203,7 +238,7 @@ graph IR in parts (e.g., OpenVINO stores its IR and weights separately).</p>
203238
</ul>
204239
<h5>Return values</h5>
205240
<ul>
206-
<li><a name="method_graph.init_execution_context.0"></a> result&lt;own&lt;<a href="#graph_execution_context"><a href="#graph_execution_context"><code>graph-execution-context</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
241+
<li><a name="method_graph.init_execution_context.0"></a> result&lt;own&lt;<a href="#graph_execution_context"><a href="#graph_execution_context"><code>graph-execution-context</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
207242
</ul>
208243
<h4><a name="load"><code>load: func</code></a></h4>
209244
<p>Load a <a href="#graph"><code>graph</code></a> from an opaque sequence of bytes to use for inference.</p>
@@ -215,7 +250,7 @@ graph IR in parts (e.g., OpenVINO stores its IR and weights separately).</p>
215250
</ul>
216251
<h5>Return values</h5>
217252
<ul>
218-
<li><a name="load.0"></a> result&lt;own&lt;<a href="#graph"><a href="#graph"><code>graph</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
253+
<li><a name="load.0"></a> result&lt;own&lt;<a href="#graph"><a href="#graph"><code>graph</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
219254
</ul>
220255
<h4><a name="load_by_name"><code>load-by-name: func</code></a></h4>
221256
<p>Load a <a href="#graph"><code>graph</code></a> by name.</p>
@@ -228,5 +263,5 @@ range from simple to complex (e.g., URLs?) and caching mechanisms of various kin
228263
</ul>
229264
<h5>Return values</h5>
230265
<ul>
231-
<li><a name="load_by_name.0"></a> result&lt;own&lt;<a href="#graph"><a href="#graph"><code>graph</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
266+
<li><a name="load_by_name.0"></a> result&lt;own&lt;<a href="#graph"><a href="#graph"><code>graph</code></a></a>&gt;, own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;&gt;</li>
232267
</ul>

wit/wasi-nn.wit

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,35 @@ interface inference {
133133

134134
/// TODO: create function-specific errors (https://github.com/WebAssembly/wasi-nn/issues/42)
135135
interface errors {
136-
enum error {
136+
enum error-code {
137137
// Caller module passed an invalid argument.
138138
invalid-argument,
139139
// Invalid encoding.
140140
invalid-encoding,
141-
busy,
141+
// The operation timed out.
142+
timeout,
142143
// Runtime Error.
143144
runtime-error,
144145
// Unsupported operation.
145146
unsupported-operation,
146147
// Graph is too large.
147148
too-large,
148149
// Graph not found.
149-
not-found
150+
not-found,
151+
// The operation is insecure or has insufficient privilege to be performed.
152+
// e.g., cannot access a hardware feature requested
153+
security,
154+
// The operation failed for an unspecified reason.
155+
unknown
156+
}
157+
158+
resource error {
159+
constructor(code: error-code, data: string);
160+
161+
/// Return the error code.
162+
code: func() -> error-code;
163+
164+
/// Errors can propagated with backend specific status through a string value.
165+
data: func() -> string;
150166
}
151167
}

0 commit comments

Comments
 (0)