dbg()

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

Signature

dbg()(message: T) => T

Description

The dbg() (debug) method outputs message in the summary of query responses and returns message in the query result. In the summary, debug messages are annotated as info.

dbg() and log()

dbg() is similar to log() except that dbg() returns its message in the actual query result.

You can use dbg() inline within method calls for debugging.

Debug message template

The debug 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 summary and query results.

Return value

Type Description

Any

Returns message.

Examples

  1. Output a composed value in the query response:

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

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

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

See also

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!