Skip to content

Misleading error for unexpected argument of data in pdf.embed #6394

@197g

Description

@197g

Description

The pdf.embed function is documented as taking an optional positional argument for file data. However, that the argument is interpreted as none—and consequentially ignored—if it is anything but bytes. This leads to hard to diagnose behavior when such data is supplied by decoding (i.e. cbor) or has otherwise dynamic type. Instead, the implementation tries to read the actual file referenced by the path. Note this fault may silently incorrectly (!) succeed.

#pdf.embed("example.txt", "oops-this-is-text")
error: file not found (searched at /tmp/example.txt)
  ┌─ what.typ:1:11
  │
1 │ #pdf.embed("example.txt", "oops-this-is-text")
  │            ^^^^^^^^^^^^^

Expected behavior

error: invalid argument type, expected bytes, got string
  ┌─ what.typ:1:11
  │
1 │ #pdf.embed("example.txt", "oops-this-is-text")
  │                           ^^^^^^^^^^^^^^^^^^^

Reproduction URL

No response

Operating system

Linux

Typst version

  • I am using the latest version of Typst

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood contributionSuitable for contribution, but unlike "good first issue", it may need prior experiencepdfRelated to PDF export or PDF embedding.scriptingAbout Typst's coding capabilities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions