Step
Calculator
Message
Cannot read properties of undefined (Reading '{some variable}' )
Cause
This error means that the calculator code is trying to access an object property that does not exist. For example, given an object
jsx
const myObject = {
innerObject1: {
x: 1
}
}
const myX = myObject.innerObject1.x; // Valid, the given property exists
const myZ = myObject.innerObject3.z; // Invalid, innerObject2 is undefined.
// trying to read the value y from it
// results in the above error
Reading `myObject.innerObject1.x` is valid because the full path is valid.
Reading `myObject.innerObject3.z` is invalid because innerObject3 is undefined.
Trying to read the value `y` from it results in the above error.
Resolution
Use optional chaining to avoid errors. The following will throw an error if innerObject3 is undefined
jsx
const myZ = myObject.innerObject3.z //
Try the following to resolve:
```jsx
const myZ = myObject.innerObject3?.z // Will not throw error, instead myZ will be null
if(myZ){
// do something with myZ
}else{
// myZ is undefined
}
```
Error Detail
{
"message": "Error running calculation",
"statusCode": 400,
"error": {},
"errorMessage": "Cannot read properties of undefined (reading 'Record')"
}