Skip to content

Commit f71255a

Browse files
authored
feat(native): Correct error handling for neon::channel.send (#6106)
1 parent 4524579 commit f71255a

File tree

3 files changed

+57
-49
lines changed

3 files changed

+57
-49
lines changed

packages/cubejs-backend-native/Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cubejs-backend-native/src/channel.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,31 @@ where
115115
tx.send(to_channel).unwrap();
116116
}));
117117

118-
channel.send(move |mut cx| {
119-
// https://github.com/neon-bindings/neon/issues/672
120-
let method = match Arc::try_unwrap(js_method) {
121-
Ok(v) => v.into_inner(&mut cx),
122-
Err(v) => v.as_ref().to_inner(&mut cx),
123-
};
124-
125-
let this = cx.undefined();
126-
let args: Vec<Handle<JsValue>> = vec![
127-
if let Some(q) = query {
128-
cx.string(q).upcast::<JsValue>()
129-
} else {
130-
cx.null().upcast::<JsValue>()
131-
},
132-
async_channel.to_object(&mut cx)?.upcast::<JsValue>(),
133-
];
134-
135-
method.call(&mut cx, this, args)?;
136-
137-
Ok(())
138-
});
118+
channel
119+
.try_send(move |mut cx| {
120+
// https://github.com/neon-bindings/neon/issues/672
121+
let method = match Arc::try_unwrap(js_method) {
122+
Ok(v) => v.into_inner(&mut cx),
123+
Err(v) => v.as_ref().to_inner(&mut cx),
124+
};
125+
126+
let this = cx.undefined();
127+
let args: Vec<Handle<JsValue>> = vec![
128+
if let Some(q) = query {
129+
cx.string(q).upcast::<JsValue>()
130+
} else {
131+
cx.null().upcast::<JsValue>()
132+
},
133+
async_channel.to_object(&mut cx)?.upcast::<JsValue>(),
134+
];
135+
136+
method.call(&mut cx, this, args)?;
137+
138+
Ok(())
139+
})
140+
.map_err(|err| {
141+
CubeError::internal(format!("Unable to send js call via channel, err: {}", err))
142+
})?;
139143

140144
rx.await?
141145
}

packages/cubejs-backend-native/src/stream.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,28 +163,32 @@ pub fn call_js_with_stream_as_callback(
163163
let buffer = Arc::new(Buffer::new());
164164
let writer = buffer.clone();
165165

166-
channel.send(move |mut cx| {
167-
// https://github.com/neon-bindings/neon/issues/672
168-
let method = match Arc::try_unwrap(js_method) {
169-
Ok(v) => v.into_inner(&mut cx),
170-
Err(v) => v.as_ref().to_inner(&mut cx),
171-
};
172-
173-
let stream = JsWriteStream { writer };
174-
175-
let this = cx.undefined();
176-
let args: Vec<Handle<_>> = vec![
177-
if let Some(q) = query {
178-
cx.string(q).upcast::<JsValue>()
179-
} else {
180-
cx.null().upcast::<JsValue>()
181-
},
182-
stream.to_object(&mut cx)?.upcast::<JsValue>(),
183-
];
184-
method.call(&mut cx, this, args)?;
185-
186-
Ok(())
187-
});
166+
channel
167+
.try_send(move |mut cx| {
168+
// https://github.com/neon-bindings/neon/issues/672
169+
let method = match Arc::try_unwrap(js_method) {
170+
Ok(v) => v.into_inner(&mut cx),
171+
Err(v) => v.as_ref().to_inner(&mut cx),
172+
};
173+
174+
let stream = JsWriteStream { writer };
175+
176+
let this = cx.undefined();
177+
let args: Vec<Handle<_>> = vec![
178+
if let Some(q) = query {
179+
cx.string(q).upcast::<JsValue>()
180+
} else {
181+
cx.null().upcast::<JsValue>()
182+
},
183+
stream.to_object(&mut cx)?.upcast::<JsValue>(),
184+
];
185+
method.call(&mut cx, this, args)?;
186+
187+
Ok(())
188+
})
189+
.map_err(|err| {
190+
CubeError::internal(format!("Unable to send js call via channel, err: {}", err))
191+
})?;
188192

189193
Ok(buffer)
190194
}

0 commit comments

Comments
 (0)