enketo/enketo-express

Error handling after load error

Closed this issue · 2 comments

I was looking at #201 and noticed that there are actually two error messages shown in the console. One is described by #201, but the other seems to be related to how a load error is handled:

Uncaught (in promise) TypeError: Cannot read property 'languages' of undefined

This message isn't shown to the user outside the console: only the messages from #201 are shown outside the console. However, this TypeError seems to stem from a different part of the code from #201 (enketo-express instead of enketo-core), so I thought I'd file a second issue.

The TypeError seems to be thrown by the last line here:

function _init( formParts ) {
formheader.after( formParts.formFragment );
const formEl = document.querySelector( 'form.or' );
localize( formEl );
controller.init( formEl, {
modelStr: formParts.model,
instanceStr: formParts.instance,
external: formParts.externalData,
instanceAttachments: formParts.instanceAttachments,
} ).then( form => {
formParts.languages = form.languages;

I think what's happening is that even after a load error, controller.init() returns a fulfilled promise, but one in which form is undefined. I think Enketo Express could prevent this message from appearing in the console by:

  • Checking in the then() callback here whether form exists
  • Alternatively, having the catch() callback in controller.init() rethrow the error, then adding a catch() callback here

The text of the error message above is from Chrome. The text is slightly different in other browsers:

  • Firefox: Uncaught (in promise) TypeError: t is undefined
  • Safari: Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 't.languages')

CC @lognaturel

Thank you!

Regular: http://localhost:8005/YYpM
View: http://localhost:8005/view/acefc9353e1386051bec92da9669bda3
Edit:

curl --user enketorules: -d "server_url=https:/enketo-aggregate.appspot.com&form_id=vitals&instance_id=a&instance=<demo-vitals-grid><page2><bp_yn>1</bp_yn></page2></demo-vitals-grid>" http://localhost:8005/api/v2/instance

I've attempted to move this issue to https://github.com/enketo/enketo a number of times over the past couple of days and it always fails. Now transfer attempts create ghost issues like enketo/enketo#1284 I don't think it's very important so this issue will stay here!