LynxError API

LynxError is the standard error object returned by the Lynx runtime to indicate runtime failures, warnings, or recoverable issues in your app.

It contains both machine-readable information (error code, subcode, severity level) and a human-readable message to help with debugging and recovery.

Use Cases

  • Display meaningful errors in debug or development mode
  • Trigger fallback UI or navigation for fatal runtime issues
  • Report errors for analytics or bug tracking

Core Concepts

Error Code

A 3–4 digit number identifying the category or behavior of an error. For example, 301 represents an image loading error.

Refer to the Error Codes documentation for a full list of codes and their meanings.

Subcode

A 5–6 digit number derived from the error code, used to specify the exact cause of the error. For example, 30101 indicates that the loaded image is too large.

Refer to the Error Codes documentation for details on individual subcodes.

Level

LynxError defines four levels: Fatal, Error, Warn, and Undecided.

LevelMeaningSuggested Action
FatalApp is likely unusableReload or fallback UI
ErrorRecoverable issueLog and retry
WarnNon-blocking warningLog and continue
UndecidedNot yet categorizedHandle gracefully, log issue

Message

A JSON-formatted string containing detailed error information, including:

  • code
  • subcode
  • level
  • message
  • suggestion (optional)

Platform Methods

Android

MethodReturn TypeDescription
getErrorCode()intReturns the error code
getSubCode()intReturns the subcode
getLevel()StringReturns the level
getMsg()StringReturns the message

iOS

Property / MethodTypeDescription
errorCodeNSIntegerReturns the error code
subcodeNSIntegerReturns the subcode
levelNSString*Returns the level
userInfo()NSDictionary*Returns a dictionary where the message can be queried using the key LynxErrorUserInfoKeyMessage

HarmonyOS

MethodTypeDescription
getErrorCode()numberReturns the error code
getSubCode()numberReturns the subcode
getLevel()LynxErrorLevelReturns the level
getMsg()stringReturns the message

Example

JavaScript

lynx.onError((err) => {
  if (err.getLevel() === 'Fatal') {
    // Possibly reload or fallback to home
    console.error('Critical error occurred:', err.getMsg());
  }
});

Kotlin

fun onLynxError(error: LynxError) {
  if (error.level == "Fatal") {
    println("Fatal error: ${error.msg}")
  }
}

Swift

func onLynxError(_ error: LynxError) {
  if error.level == "Fatal" {
    print("Fatal error: \(error.msg)")
  }
}

ETS

onLynxError(error: LynxError) {
  if (error.level == LynxErrorLevel.Fatal) {
    console.error('Fatal error:', error.getMsg());
  }
}

Compatibility

LCD tables only load in the browser

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.