Logging errors
The Console API in the Modus SDK is globally available in all functions. It allows developers to capture log messages and errors, which are automatically included in Modus runtime execution logs.When deployed to Hypermode, function logs are available in the Hypermode
Console on the Function Runs page.
Error reporting in GraphQL
GraphQL responses have a standard structure that includes bothdata
and
errors
sections. Modus allows for the inclusion of error codes or messages
within the errors
section to allow for downstream processing in addition to
debugging.
Best practices for error handling
-
Handle non-fatal errors using
console.error
, allowing the function to continue. The GraphQL response may have both adata
section and anerrors
section. -
Handle critical errors using AssemblyScript
throw
keyword or the Go idiomatic error object to stop the function’s execution. - Return clear error messages: When returning errors, include concise and informative error messages that help diagnose the issue.