Skip to content

Commit

Permalink
add unstable exit-with-code function (#44)
Browse files Browse the repository at this point in the history
* add unstable `exit-with-code` function

Whereas the existing `exit` function only accepts a `result` parameter
(i.e. binary success or failure), this function allows the instance to report
any status code from 0 to 255 to the host, with 0 usually meaning "success" and
other values having their own meaning depending on the context.

Fixes #11

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

---------

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Co-authored-by: Bailey Hayes <behayes2@gmail.com>
  • Loading branch information
dicej and ricochet committed Aug 1, 2024
1 parent 6d41983 commit 1d8439d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ jobs:
git diff --exit-code
- uses: WebAssembly/wit-abi-up-to-date@v21
with:
worlds: "command imports"
wit-bindgen: '0.28.0'
worlds: 'command imports'
features: 'cli-exit-with-code'
11 changes: 11 additions & 0 deletions command.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ directory, interpreting <code>.</code> as shorthand for this.</p>
<ul>
<li><a name="exit.status"></a><code>status</code>: result</li>
</ul>
<h4><a name="exit_with_code"></a><code>exit-with-code: func</code></h4>
<p>Exit the current instance and any linked instances, reporting the
specified status code to the host.</p>
<p>The meaning of the code depends on the context, with 0 usually meaning
&quot;success&quot;, and other values indicating various types of failure.</p>
<p>This function does not return; the effect is analogous to a trap, but
without the connotation that something bad has happened.</p>
<h5>Params</h5>
<ul>
<li><a name="exit_with_code.status_code"></a><code>status-code</code>: <code>u8</code></li>
</ul>
<h2><a name="wasi_io_error_0_2_0"></a>Import interface wasi:io/error@0.2.0</h2>
<hr />
<h3>Types</h3>
Expand Down
11 changes: 11 additions & 0 deletions imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ directory, interpreting <code>.</code> as shorthand for this.</p>
<ul>
<li><a name="exit.status"></a><code>status</code>: result</li>
</ul>
<h4><a name="exit_with_code"></a><code>exit-with-code: func</code></h4>
<p>Exit the current instance and any linked instances, reporting the
specified status code to the host.</p>
<p>The meaning of the code depends on the context, with 0 usually meaning
&quot;success&quot;, and other values indicating various types of failure.</p>
<p>This function does not return; the effect is analogous to a trap, but
without the connotation that something bad has happened.</p>
<h5>Params</h5>
<ul>
<li><a name="exit_with_code.status_code"></a><code>status-code</code>: <code>u8</code></li>
</ul>
<h2><a name="wasi_io_error_0_2_0"></a>Import interface wasi:io/error@0.2.0</h2>
<hr />
<h3>Types</h3>
Expand Down
11 changes: 11 additions & 0 deletions wit/exit.wit
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@ interface exit {
/// Exit the current instance and any linked instances.
@since(version = 0.2.0)
exit: func(status: result);

/// Exit the current instance and any linked instances, reporting the
/// specified status code to the host.
///
/// The meaning of the code depends on the context, with 0 usually meaning
/// "success", and other values indicating various types of failure.
///
/// This function does not return; the effect is analogous to a trap, but
/// without the connotation that something bad has happened.
@unstable(feature = cli-exit-with-code)
exit-with-code: func(status-code: u8);
}

0 comments on commit 1d8439d

Please sign in to comment.