Skip to content

Better error messages with argument sinks #201

Closed

Description

@AndyBarcia

Currently, when passing an incorrect type to a value, a helpful error message is shown, with the expected kind of values, and the atual value.

error: expected auto, relative length, fraction, integer, or array, found color
   ┌─ main.typ:26:10
   │
26 │   columns: blue,
   │            ^^^^

But doesn't occur with varidic parameters or "argument sinks"

#table(
	columns: 2,
	..range(0,8).map((x) => 2*x)
)

In this case, a simple "unexpected argument" is shown, without any other explanation.

error: unexpected argument
   ┌─ main.typ:22:3
   │
22 │   ..range(0,8).map((x) => 2*x)
   │     ^^^^^^^^^^^^^^^^^^^^^^^^^^

This is due to, I believe, argument sinks consuming all remaining argument of its expected type, and ignoring all other arguments. Then, if any non-consumed argument remains, an "unexpected argument" error is shown. This is fine for normal functions, but for varidic functions this error is rather non-explanatory.

I think that a more beginer-friendly implemenation would be to consume all remaining arguments, no matter its type, and then report errors accordingly if a non-castable value is found.
I haven't used Typst for that long, so if there's a problem with this hypothetical implementation, let me know.

Activity

  1. added
    scripting
    diagnostics
    on Apr 2, 2023
  2. tingerrr commented on Oct 13, 2023

    @tingerrr
    Contributor

    I think this can be closed, b471ac7 introduced a fix for this by retaining the errors and displaying them, however it also displays one error per argument even if they all share the same error reason and span, I think this can be improved and would PR that if I get a nice solution for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsscripting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions