Returns the LensScriptError behind a Lens failure, or undefined if none was created. That happens
when the failure wasn't the Lens's script (for example, the Lens could not be downloaded or one of its assets
could not be loaded), or when the script threw something other than an Error — see LensScriptError.
A Lens script can throw at two moments, and this works the same for both:
// 1. While the Lens is being applied: applyLens rejects with a LensError. try { awaitcameraKitSession.applyLens(lens) } catch (error) { constscriptError = findLensScriptError(error) if (scriptError) console.log(`Lens ${lens.name} failed to start:\n${scriptError.stack}`) }
// 2. While the Lens is rendering: Camera Kit removes the Lens and emits a LensExecutionError. cameraKitSession.events.addEventListener('error', ({ detail }) => { constscriptError = findLensScriptError(detail.error) if (scriptError) { console.log(`Lens ${detail.lens.name} has a script error:\n${scriptError.stack}`) } else { console.log(`Lens ${detail.lens.name} encountered an error and was removed.`) } })
The stack looks like this:
LensScriptError: TypeError: cannot read property 'text' of undefined
at onTap (Scripts/TapHandler.js:18:22)
at apply (native)
at <anonymous> (Scripts/TapHandler.js:9:5)
Parameters
error: unknown
Any error emitted by Camera Kit. Values that are not an Error return undefined.
Returns the LensScriptError behind a Lens failure, or
undefinedif none was created. That happens when the failure wasn't the Lens's script (for example, the Lens could not be downloaded or one of its assets could not be loaded), or when the script threw something other than anError— see LensScriptError.A Lens script can throw at two moments, and this works the same for both:
The stack looks like this: