dbg()

Output a message in the query response and return the message.

Signature

dbg()(message: T): T

Description

The dbg() method outputs message in the query response summary field and returns message. It includes a preview of the calling location.

The message template is:

info: <message>
at *<source>*:<line>:<column>
       |
<line> | dbg(<message>)
       |    ^^^^^^^^^^^
       |

where:

Field Description

<source>

Message source.
One of:

Source Description

query

The dbg() call occurred in the main query body.

udf:<function>

The dbg() call occurred in the user-defined function named <function>

<line>

Line number where dbg() is used.

<column>

Character offset in <line> where dbg() is used.

<message>

String-serialized message.

Parameters

Parameter Type Required Description

message

Any

Yes

Value to output to the query response.

Return value

Type Description

Any

Returns message.

Examples

  1. Output a composed value in the query response:

    Product.create({
      name: "debug1",
      quantity: dbg(1 + 2 + 3),
    })
    info: 6
    at *query*:3:16
      |
    3 |   quantity: dbg(1 + 2 + 3),
      |                ^^^^^^^^^^^
      |
    
    {
      id: "394873023799230528",
      coll: Product,
      ts: Time("2099-04-11T12:38:31.050Z"),
      name: "debug1",
      quantity: 6
    }
  2. Output a Struct:

    Product.create(
      dbg({
        name: "debug2",
        quantity: 1 + 2 + 3,
      })
    )
    info: { name: "debug2", quantity: 6 }
    at *query*:2:6
      |
    2 |     dbg({
      |  ______^
    3 | |     name: "debug2",
    4 | |     quantity: 1 + 2 + 3
    5 | |   })
      | |____^
      |
    
    {
      id: "394873104675897408",
      coll: Product,
      ts: Time("2099-04-11T12:39:48.180Z"),
      name: "debug2",
      quantity: 6
    }
  3. Output a Document:

    dbg(
      Product.create({
        name: "debug3",
        quantity: 1 + 2 + 3,
      })
    )
    info: { id: ID("394873211262599234"), coll: Product, ts: TransactionTime(), name: "debug3", quantity: 6 }
    at *query*:1:4
      |
    1 |   dbg(
      |  ____^
    2 | |   Product.create({
    3 | |     name: "debug3",
    4 | |     quantity: 1 + 2 + 3,
    5 | |   })
    6 | | )
      | |_^
      |
    
    {
      id: "394873211262599234",
      coll: Product,
      ts: Time("2099-04-11T12:41:29.835Z"),
      name: "debug3",
      quantity: 6
    }

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!