Console
Capture errors and debugging information in your functions.
The Console API allows you to capture information from your functions, such as errors and other information that can help you debug your functions.
Unlike other APIs, the Console API is globally available by default in all functions, you don’t need to import it.
The Console API mimics the behavior of the AssemblyScript console
object, but directs the output to Hypermode as follows:
- All console output is available in the Hypermode UI, in the “Function Runs” section.
- Output from
console.error
is also sent to the GraphQL response. - Errors thrown with the
throw
keyword are also sent to the GraphQL response.
Example project
For your reference, an example that uses the Console APIs is available on GitHub in the
hypermodeAI/functions-as
repository, at /examples/simple.
You’ll also find the Console APIs used throughout other examples in the repository.
Console APIs
The APIs in the console
namespace are below, organized by category.
We’re constantly introducing new APIs through ongoing development with build partners. Let’s chat about what would make the Functions SDK even more powerful for your next use case!
Assertion Functions
assert
Asserts that a condition is true, and logs an error if it’s not.
The condition to assert. Typically a boolean value. In the case of an object,
asserts that the object isn’t null
.
An error message to log, if the assertion is false.
Logging Functions
log
Generate a log message, with no particular logging level.
A message you want to log.
debug
Generate a log message with the “debug” logging level.
A debug message you want to log.
info
Generate a log message with the “info” logging level.
An informational message you want to log.
warn
Generate a log message with the “warning” logging level.
A warning message you want to log.
error
Generate a log message with the “error” logging level.
An error message you want to log.
Timing Functions
time
Starts a new timer using the specified label.
An optional label for the timer.
timeLog
Logs the current value of a timer previously started with console.time
.
An optional label for the timer.
timeEnd
Logs the current value of a timer previously started with console.time
, and discards the timer.
An optional label for the timer.