Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm httplib replacement2 #3

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/include/wasm_httplib_replacement.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <emscripten.h>
#include "duckdb/common/exception.hpp"

namespace duckdb {

Expand Down Expand Up @@ -26,7 +27,11 @@ struct WasmClient {
const xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.responseType = "arraybuffer";
xhr.send(null);
try {
xhr.send(null);
} catch {
return 0;
}
if (xhr.status != 200)
return 0;
var uInt8Array = xhr.response;
Expand Down Expand Up @@ -59,8 +64,8 @@ struct WasmClient {
path.c_str());

if (!exe) {
res._inner.status = 404;
res._inner.reason = "Something went quack in Wasm land!";
res._inner.status = 400;
res._inner.reason = "Unknown error, something went quack in Wasm land! Please consult the console and or the docs at https://duckdb.org/community_extensions/extensions/webmacro";
} else {
res._inner.status = 200;
uint64_t LEN = 0;
Expand All @@ -87,6 +92,8 @@ SetupHttpClient(const std::string &url) {
}

static void HandleHttpError(const WasmResult &res,
const std::string &request_type) {}
const std::string &request_type) {
throw HTTPException("Unknown problem while perfoming XMLHttpRequest");
}

} // namespace duckdb
6 changes: 4 additions & 2 deletions src/webmacro_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static void LoadMacroFromUrlFunction(DataChunk &args, ExpressionState &state, Ve
}

if (res->status != 200) {
throw std::runtime_error("HTTP error " + std::to_string(res->status) + ": " + res->reason);
throw HTTPException(std::to_string(res->status) + ": " + res->reason);
}

// Get the SQL content
Expand Down Expand Up @@ -208,7 +208,9 @@ static void LoadMacroFromUrlFunction(DataChunk &args, ExpressionState &state, Ve

return StringVector::AddString(result, "Successfully loaded macro: " + macro_name);

} catch (std::exception &e) {
} catch (duckdb::HTTPException &e) {
throw;
} catch (std::exception &e) {
std::string error_msg = "Error: " + std::string(e.what());
throw std::runtime_error(error_msg);
}
Expand Down
Loading