Homey Community Forum

Swedish holiday app crashing on homey 5.0 exper

Several of my users using the swedish holiday app is getting crashes together with Homey 5.0 experimental version. Never had any crashes on the old versions and me code seems to be aligned with the SKD. Anybody that can spot the problem?

/app.js:6
const TodaySwedishHolidayToken = new Homey.FlowToken(‘TodaySwedishHoliday’, {type: ‘boolean’,title: this.homey.__(“TodaySwedishHoliday”)});
^

TypeError: Cannot read property ‘__’ of undefined
at Object. (/app.js:6:112)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at Module.require (/opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/index.js:1:191)
at require (internal/modules/cjs/helpers.js:77:18)
at /opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/lib/SDK.js:1:3491
at FSReqCallback.oncomplete (fs.js:167:5)

Tried changing it so it matches SDK3, but that dosent fix it:

/app.js:6
const TodaySwedishHolidayToken = new Homey.FlowToken(‘TodaySwedishHoliday’, {type: ‘boolean’,title: this.homey.__(“TodaySwedishHoliday”)});
^

TypeError: Cannot read property ‘__’ of undefined
at Object. (/app.js:6:112)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at Module.require (/opt/homey-client/node_modules/homey-apps-sdk-v2/index.js:14:19)
at require (internal/modules/cjs/helpers.js:77:18)
at /opt/homey-client/node_modules/homey-apps-sdk-v2/lib/SDK.js:212:28
at FSReqCallback.oncomplete (fs.js:167:5)

It seems that underscore “_” is not allowed here (anymore?)

Same problem if i remove :frowning:

─────────────── Logging stdout & stderr ───────────────
/app.js:5
console.log( Homey.(“title”) ); // “Hello World”
^

SyntaxError: Unexpected token '('
    at wrapSafe (internal/modules/cjs/loader.js:1072:16)
    at Module._compile (internal/modules/cjs/loader.js:1122:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at Module.require (/opt/homey-client/node_modules/homey-apps-sdk-v2/index.js:14:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at /opt/homey-client/node_modules/homey-apps-sdk-v2/lib/SDK.js:212:28
    at FSReqCallback.oncomplete (fs.js:167:5)

--- INFO: se.faboul.svenskahelgdagar has been killed ---

I believe another developer ran into the same problem, for some reason the __ method isn’t available from this.homey. This seems like a bug, because the method is still documented.

Perhaps Homey.__ still works and they forgot to move it. Otherwise, you’ll have to report the issue to Athom and hope they’ll provide a fix soon.

Thanks! The response from homey support is

""Thank you for contacting Homey customer support! Your question seems to be developer-related and unfortunately we cannot assist you with these kind of questions.

Luckily Homey has a very active community that is eager to help. You can ask your question on the following resources…"

Ah looking at it a little closer, it may indeed be developer error. It depends on what this refers to in the context of the code where you use it. Can you point to the line of the code in question on Github (provided that you have it stored there)?

App has probably covid-19

At the moment the code looks like this, see row 6

Notice that this was a working code with no bug reports until Homey 5.0

Solved it now! moved All the const’s in “//Create tokens” to begin after oninit :=)

So Homey.__ outside of your class doesn’t work, but inside your class it does?

When the app.js file is loaded, your app isn’t initialized yet. It isn’t documented (of course), but apparently, you can only use the Homey.__() function after app initialization, which isn’t that weird.

I really, really recommend sticking those variables to some class though, instead of having them floating around in globals… If you stick them in your app class, you can access them everywhere through Homey.app.

It’s a misconception (one that seems to be propagated by Athom themselves) that a variable that gets declared in the outside scope of a module (or .js file) is a global. It’s not.

Globals in Node.js terms are real globals (available from every file without having to import them explicitly), and I don’t think you can even create them from normal code.

Importing modules, like const { Homey } = require('homey'), creates a module-scoped variable, and there’s nothing wrong with that.

In fact, I don’t really like the idea of having a magic this.homey made available in every Homey.* class. It’s way too implicit. It would have been better IMO to pass it as an argument to the constructor, for instance (explicit dependency injection).