Configuring truthy value to transitions fails

This document mentions about configuring transitions in a truthy value. I am not sure when was it changed to be truthy value, but in our older sms configurations, we were using transitions to be set like this:

"transitions": {
    "accept_patient_reports": {
      "load": "./transitions/accept_patient_reports.js"
    },
    "conditional_alerts": {
      "load": "./transitions/conditional_alerts.js"
    },
    "default_responses": {
      "load": "./transitions/default_responses.js"
    },
    "update_sent_by": {
      "load": "./transitions/update_sent_by.js"
    },
    "registration": {
      "load": "./transitions/registration.js"
    },
    "update_clinics": {
      "load": "./transitions/update_clinics.js"
    },
    "update_notifications": {
      "load": "./transitions/update_notifications.js"
    },
    "update_scheduled_reports": {
      "load": "./transitions/update_scheduled_reports.js"
    },
    "update_sent_forms": {
      "load": "./transitions/update_sent_forms.js"
    }
  }

Which appears to be referencing the transtion files here.

Most of our instances were on CHT 2.x and 3.6/7/8 and all had transitions like shown above.

Recently, we upgraded our CHT instances to up to 3.16 and as per documentation, we updated transitions to be on truthy value. However, we’re getting unseen errors because of this on different transitions. Until recently, we were seeing problem only on update_notifications and we replaced truthy value to look like how we used previously:

 "update_notifications": {
      "load": "./transitions/update_notifications.js"
    },

Now, in some instances running on 3.16, we’re also seeing an issue with registration transition. Below is the log:

2023-01-29 20:50:57 ERROR: UNHANDLED REJECTION! 
2023-01-29 20:50:57 ERROR:   Reason: TypeError: Cannot read properties of undefined (reading 'registrations')
    at Object.get (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/config.js:10:21)
    at getConfig (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/transitions/registration.js:188:32)
    at Object.filter (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/transitions/registration.js:671:29)
    at canRun (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/transitions/index.js:221:16)
    at applyTransition (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/transitions/index.js:271:18)
    at wrapper (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/lodash/lodash.js:5213:19)
    at /Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/async/dist/async.js:3669:28
    at replenish (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/async/dist/async.js:446:21)
    at iterateeCallback (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/async/dist/async.js:430:21)
    at /Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/async/dist/async.js:327:20 {
  [stack]: "TypeError: Cannot read properties of undefined (reading 'registrations')\n" +
    '    at Object.get (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/config.js:10:21)\n' +
    '    at getConfig (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/transitions/registration.js:188:32)\n' +
    '    at Object.filter (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/transitions/registration.js:671:29)\n' +
    '    at canRun (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/transitions/index.js:221:16)\n' +
    '    at applyTransition (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/@medic/transitions/src/transitions/index.js:271:18)\n' +
    '    at wrapper (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/lodash/lodash.js:5213:19)\n' +
    '    at /Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/async/dist/async.js:3669:28\n' +
    '    at replenish (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/async/dist/async.js:446:21)\n' +
    '    at iterateeCallback (/Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/async/dist/async.js:430:21)\n' +
    '    at /Users/yuvraj/.horticulturalist/deployments/medic-api/md5-IaUJW7p4rpaMwbWhKl5C1A==/node_modules/async/dist/async.js:327:20',
  [message]: "Cannot read properties of undefined (reading 'registrations')"
} 

We are updating registration transition to follow the older pattern of loading file and it’s working so far now.

Why setting truthy value for transitions is failing? What’s the difference in setting it to truthy value vs loading the transition file?

Hi @yuv !

Can you please share an example of the configuration with the truthy value?

Are there any other errors in the log before this one? I’m hoping to see a error loading the configuration.

I’m not quite sure what’s going on yet, but it looks like the app configuration is undefined when API is loading the registrations configuration. I suspect that when you set the truthy value it’s not loading the transitions so the error isn’t showing then.

Hi @gareth , here’s the example of our configuration with both truthy value and load transition. This is one of our production configuration. Initially, all these transitions were set to true. We needed to updated registration to load, just like update_notifications, and it’s working fine now.

  "transitions": {
    "accept_patient_reports": true,
    "conditional_alerts": true,
    "default_responses": true,
    "update_sent_by": true,
    "registration": {
      "load":"./transitions/registration.js"
    },
    "update_clinics": true,
    "update_notifications": {
      "load": "./transitions/update_notifications.js"
    }
    ,"update_scheduled_reports": true
  }

Are there any other errors in the log before this one? I’m hoping to see a error loading the configuration.

There is no other error log before aforementioned log. However, below is the log just before failure.

REQ e9b552b0-c6ca-4b8a-8575-71619055729f ::1 - POST /medic-user-admin-meta/_all_docs? HTTP/1.1
REQ 7faf8a2b-e28e-4290-9114-def2534bf04b ::1 - GET /medic/281354b2-31f2-40e1-928b-ddabd5e02eb5? HTTP/1.1
REQ 0d7e415c-686b-46c3-941b-7816471799ef ::1 - POST /medic-user-admin-meta/_bulk_docs HTTP/1.1
RES 7faf8a2b-e28e-4290-9114-def2534bf04b ::1 - GET /medic/281354b2-31f2-40e1-928b-ddabd5e02eb5? HTTP/1.1 304 0 171.432 ms
RES 0d7e415c-686b-46c3-941b-7816471799ef ::1 - POST /medic-user-admin-meta/_bulk_docs HTTP/1.1 201 116 260.874 ms
RES e9b552b0-c6ca-4b8a-8575-71619055729f ::1 - POST /medic-user-admin-meta/_all_docs? HTTP/1.1 200 - 219.379 ms
REQ ea9ba39a-807c-46fa-9d3f-713dac149145 ::1 - GET /service-worker.js HTTP/1.1
RES ea9ba39a-807c-46fa-9d3f-713dac149145 ::1 - GET /service-worker.js HTTP/1.1 304 - 18.646 ms
REQ 93b24f8c-48b7-44b2-bdd0-4bd64da645c2 ::1 - GET /service-worker.js HTTP/1.1
RES 93b24f8c-48b7-44b2-bdd0-4bd64da645c2 ::1 - GET /service-worker.js HTTP/1.1 304 - 10.811 ms
RES fc14b82c-3c83-41ac-b43f-3653b445c0f8 ::1 admin POST /api/v2/records HTTP/1.1 - - - ms
2023-01-29 20:48:18 DEBUG: Checking for a configured outgoing message service 
2023-01-29 20:49:18 DEBUG: Checking for a configured outgoing message service 
2023-01-29 20:50:18 DEBUG: Checking for a configured outgoing message service 
REQ 036e3a66-ed3a-47b8-bd2c-e8a8aa524a45 ::1 admin POST /api/v2/records HTTP/1.1
2023-01-29 20:50:57 DEBUG: isRevSame tested false on transition update_clinics for doc 3f620066-6201-42df-83fb-5b97bdc8ffaa seq null 
2023-01-29 20:50:57 DEBUG: calling transition.onMatch for doc 3f620066-6201-42df-83fb-5b97bdc8ffaa and transition update_clinics seq null 
2023-01-29 20:50:57 DEBUG: finished transition update_clinics doc 3f620066-6201-42df-83fb-5b97bdc8ffaa is changed seq null 
2023-01-29 20:50:57 DEBUG: isRevSame tested false on transition registration for doc 3f620066-6201-42df-83fb-5b97bdc8ffaa seq null 
2023-01-29 20:50:57 ERROR: UNHANDLED REJECTION! 
2023-01-29 20:50:57 ERROR:   Reason: TypeError: Cannot read properties of undefined (reading 'registrations')

What about when you first start the instance? I’m expecting to see something go wrong when the settings are initialised.

Looking more closely I think it’s caused by this issue. Upgrade to 3.16.1 to fix the issue.

We’ll upgrade instanes to 3.16.1 and let you know.

We upgraded all of the instances to 3.17.1 and we are not facing these issues. 3.16.1 or 3.17.1 would not have this issue.

1 Like