Debugging Transformation Errors
5 minute read
This guide lists the different errors you might encounter while using transformations and libraries, and how to fix them.
JavaScript
ReferenceError
This error occurs when a non-existent variable is referenced somewhere in the transformation.
TypeError
This error occurs when a property is read or function is called on an undefined variable.
| Sample code and error | Possible solution |
|---|---|
export function transformEvent(event, metadata) {Error: “TypeError: Cannot read properties of” | Use optional chaining when accessing nested fields.event.val = event.context?.traits?.obj?.val1; |
SyntaxError
This error occurs when you run a syntactically invalid code, that is, it does not conform to the language syntax. For example, SyntaxError: Unexpected identifier, SyntaxError: Unexpected token.
| Sample code and error | Possible solution |
|---|---|
export function transformEvent(event, metadata) {Error: SyntaxError: Unexpected identifier | Check your code for any misspelt keywords and missing operators/commas. |
Expected…Found error
This error occurs when you specify a transformation function other than transformEvent or transformBatch.
| Sample code and error | Possible solution |
|---|---|
export function transformEvent2(event, metadata) {Error: Error: Expected one of transformEvent,transformBatch. | Verify that the transformation function is either transformEvent or transformBatch. |
Import error
This error occurs when the module you are tring to import from a library does not exist.
| Sample code and error | Possible solution |
|---|---|
import {add} from ‘jsLib’; Error: Error: import from jsLib failed. Module not found. | Verify that the module you are trying to import exists in the transformation library. |
Python
NameError
This error occurs when when the transformation tries to access or use a variable that has not been defined or assigned a value.
| Sample code and error | Possible solution |
|---|---|
def transformEvent(event, metadata): Error: NameError(“name ‘value’ is not defined”) | Make sure variable is declared and available in the scope. You can also use an optional check:if(value): |
Library code:def sub(a, b):Transformation code: from pylibsub import sub Error: NameError("name ‘c’ is not defined") | Make sure variable is declared and available in the scope. See Error message format for more context on the error message. |
ZeroDivisionError
This error occurs when when the transformation attempts to divide a number by zero.
| Sample code and error | Possible solution |
|---|---|
def transformEvent(event, metadata): Error: ZeroDivisionError(‘division by zero’) | Verify your transformation logic. |
KeyError
This error occurs when the transformation attempts to access a dictionary item that does not exist.
| Sample code and error | Possible solution |
|---|---|
def transformEvent(event, metadata): Error: KeyError(‘obj’) | Verify the key that transformation is attempting to access exists in the dictionary. You can also set a optional chaining event like:event[‘val’] = event.get(‘context’).get( |
BadCodeError
This error occurs when the transformation contains syntactically invalid code or is trying to import an unsupported module/package.
| Sample code and error | Possible solution |
|---|---|
def transformEvent(event, metadata): Error: BadCodeError(‘invalid syntax ( | Verify the syntax of your transformation code. |
from pyLib2 import add Error: BadCodeError(“Unpermitted import(s). Supported modules / | Verify that the library imports one of the supported built-in packages and user-written libraries only. |
Exception error
This error occurs when you specify a transformation function other than transformEvent or transformBatch.
| Sample code and error | Possible solution |
|---|---|
def transformEvent2(event, metadata): Error: Exception(“Expected one of [’transformEvent’, ’transformBatch’]. | Verify that the transformation function is either transformEvent or transformBatch. |
ImportError
This error occurs when the module you are tring to import from a library does not exist or is not found.
Error message format
Standalone transformation
A typical JavaScript transformation error is shown:
ReferenceError: c is not defined
at sub (library jssublib:2:14)
at transformEvent (base transformation:4:22)
You can interpret the above error as follows:
ReferenceError: c is not defined: The actual error message.at sub (library jssublib:2:14): Module in which the error occurs (line: position).at transformEvent (base transformation:4:22): Depicts where the module is referenced in the transformation (line: position).
Transformation referencing a library
A typical Python transformation error is shown:
NameError(\"name 'c' is not defined\")
at sub (library pylibsub: line 2)
return a-b-c
at transformEvent (base transformation: line 4)
event['sub'] = sub(1,2)
You can interpret the above error as follows:
NameError("name 'c' is not defined"): The actual error message.at sub (library pylibsub: line 2): Line at which error occurred in the library.return a-b-c: Line where the error occurred.at transformEvent (base transformation: line 4): Line at which library is referenced by the base transformation.event['sub'] = sub(1,2): Line wherelibfunction is called.
