2

我正在 rust 中编写一些代码并将其编译为 wasm 以使用 lambda@edge 的 node.js 运行时运行它。我需要生成 uuid 作为此代码的一部分。我在 rust 中这样做,代码正在编译。但是当我运行时,它会抛出异常(并且在部署到 lambda 之前它在我的本地环境中,所以没有 AWS 环境问题)

panicked at 'could not retrieve random bytes for uuid: Node.js crypto module is unavailable', /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/uuid-0.8.2/src/v4.rs:31:13

Stack:

Error
    at _.exports.__wbg_new_693216e109162396 (/Users/user/tech/DataPlatform/RustLambda/build.function/origin-request.js:1:3651)
    at wasm-function[124]:0x10671
    at wasm-function[705]:0x21211
    at wasm-function[223]:0x17ad0
    at wasm-function[327]:0x1bc2e
    at wasm-function[521]:0x1ff7d
    at wasm-function[544]:0x20402
    at wasm-function[445]:0x1e9c4
    at wasm-function[303]:0x1ae09
    at wasm-function[310]:0x1b1fd


(node:36099) UnhandledPromiseRejectionWarning: RuntimeError: unreachable
    at wasm-function[223]:0x17b06
    at wasm-function[327]:0x1bc2e
    at wasm-function[521]:0x1ff7d
    at wasm-function[544]:0x20402
    at wasm-function[445]:0x1e9c4
    at wasm-function[303]:0x1ae09
    at wasm-function[310]:0x1b1fd
    at wasm-function[67]:0x59f1
    at wasm-function[320]:0x1b80b
    at wasm-function[127]:0x10b8f
(Use `node --trace-warnings ...` to show where the warning was created)
(node:36099) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:36099) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是我生锈的代码片段

        let visitor_id = Uuid::new_v4();
        debug_log!("visitor_id: {:#?}", visitor_id);
    }

我正在使用 uuid crate 作为

use uuid::Uuid;

并且依赖项在这里

uuid = { version = "0.8", features = ["v4", "wasm-bindgen"] }
getrandom = { version = "0.2", features = ["js"] }

知道如何在此处继续创建 UUID 吗?

4

0 回答 0