peng1999 / typst-pyrunner

Run python code in typst
MIT License
30 stars 0 forks source link

Datetime library causes a panic #2

Closed C-Lunn closed 8 months ago

C-Lunn commented 8 months ago
#let comp = py.compile(
        ```python
def tai_ts():
    import datetime
    n = datetime.datetime.now()
```)

causes the following error:


error: plugin panicked: wasm `unreachable` instruction executed
   ┌─ @preview/pyrunner:0.1.0/pyrunner.typ:22:14
   │
22 │   cbor.decode(py.call_compiled(compiled, bytes(fn_name), cbor.encode(args.pos())))
   │               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

help: error occurred in this call of function `call`
   ┌─ /home/ubuntu/rd-cloudfit-eagle-technote/technote_main.typ:71:1
   │
71 │ #py.call(comp, "tai_ts",)
   │  ^^^^^^^^^^^^^^^^^^^^^^^^

[2024-03-06T15:33:27Z DEBUG typst_ts_compiler::service::compile] CompileActor: fs event incoming Some(UpstreamUpdate { changeset: FileChangeSet { removes: [], inserts: [] }, upstream_event: Some(UpstreamUpdateEvent { invalidates: ["/home/ubuntu/rd-cloudfit-eagle-technote/technote_main.typ"], opaque: Any { .. } }) })
[2024-03-06T15:33:27Z INFO  typst_ts_compiler::service::diag::console] /technote_main.typ: compiling ...

[2024-03-06T15:33:27Z ERROR typst_preview::actor::typst] TypstActor: compile error: [SourceDiagnostic { severity: Error, span: Span(4892276987789304), message: "plugin panicked: wasm `unreachable` instruction executed", trace: [Call(Some("call"))], hints: [] }]
[2024-03-06T15:33:27Z INFO  typst_ts_compiler::service::diag::console] /technote_main.typ: Compilation failed after 266.055µs

error: plugin panicked: wasm `unreachable` instruction executed
   ┌─ @preview/pyrunner:0.1.0/pyrunner.typ:22:14
   │
22 │   cbor.decode(py.call_compiled(compiled, bytes(fn_name), cbor.encode(args.pos())))
   │               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

help: error occurred in this call of function `call`
   ┌─ /home/ubuntu/rd-cloudfit-eagle-technote/technote_main.typ:71:1
   │
71 │ #py.call(comp, "tai_ts",)
   │  ^^^^^^^^^^^^^^^^^^^^^^^^

Unsure what exactly is causing this as datetime is std library.

peng1999 commented 8 months ago

This code panics because there is no way for wasm plugin to access current time in Typst. I can do some trick to make datetime.now() always return the unix epoch start point. Do you think that's better?

C-Lunn commented 8 months ago

This code panics because there is no way for wasm plugin to access current time in Typst. I can do some trick to make datetime.now() always return the unix epoch start point. Do you think that's better?

That's what happens in jogs, but it's entirely up to you in that instance.