Skip to content

Commit

Permalink
Updated rust ext to deal with errors correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Moore <[email protected]>
  • Loading branch information
jimmyaxod committed Oct 9, 2023
1 parent 9dccd75 commit c22584a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion extension/generator/rust/templates/guest.rs.templ
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod types;
use crate::types::{Encode, Decode};

use std::io::Cursor;
use polyglot_rs::{Encoder};
use polyglot_rs::{Decoder, Encoder};

static HASH: &'static str = "{{ .extension_hash }}";
Expand Down Expand Up @@ -161,9 +161,19 @@ pub fn {{ $fn.Name }}(params: types::{{ $fn.Params }}) -> Result<Option<types::{
let mut l = WRITE_BUFFER.len() as u32;

{{- if (IsInterface $schema $fn.Return) }}
READ_BUFFER.resize(0, 0);
let v = _ext_{{ $schema.Name }}_{{ $fn.Name }}(0, off, l);
// IF the return type is an interface return ifc, which contains hidden instanceId.

// Check for an error
if READ_BUFFER.len() > 0 {
// Read the error and return it...
let mut cursor = Cursor::new(&mut READ_BUFFER);
if let Ok(error) = cursor.decode_error() {
return Err(error);
}
}

// TODO: Handle error from host. In this case there'll be an error in the readBuffer

let c = _{{ $fn.Return }}{
Expand Down

0 comments on commit c22584a

Please sign in to comment.