ember-fastboot / ember-fastboot/ember-cli-fastboot

_emberMetalProperty_get.get(...).getURL is not a function

Open
#223 19 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
850
Forks
161
Avg merge
17h 45m
Merged PRs (30d)
19

Description

When there is an error in an instance-initializer a very unhelpful exception is thrown. You will get the following stacktrace:

```
TypeError: _emberMetalProperty_get.get(...).getURL is not a function
at [object Object]. (.../fastboot-tryout/dist/fastboot/vendor.js:37104:60)
at Descriptor.ComputedPropertyPrototype.get (.../fastboot-tryout/dist/fastboot/vendor.js:24406:28)
at Object.get (.../fastboot-tryout/dist/fastboot/vendor.js:30060:19)
at [object Object]._emberApplicationSystemEngineInstance.default.extend.getURL (.../fastboot-tryout/dist/fastboot/vendor.js:14143:38)
at Result._finalizeMetadata (.../fastboot-tryout/node_modules/ember-cli-fastboot/node_modules/fastboot-express-middleware/node_modules/fastboot/lib/result.js:74:25)
at Result._finalize (.../fastboot-tryout/node_modules/ember-cli-fastboot/node_modules/fastboot-express-middleware/node_modules/fastboot/lib/result.js:64:12)
at .../fastboot-tryout/node_modules/ember-cli-fastboot/node_modules/fastboot-express-middleware/node_modules/fastboot/lib/ember-app.js:225:26
at tryCatch (.../fastboot-tryout/dist/fastboot/vendor.js:61543:14)
at invokeCallback (.../fastboot-tryout/dist/fastboot/vendor.js:61558:15)
at publish (.../fastboot-tryout/dist/fastboot/vendor.js:61526:9)
at .../fastboot-tryout/dist/fastboot/vendor.js:41428:7
at Queue.invokeWithOnError (.../fastboot-tryout/dist/fastboot/vendor.js:10468:18)
at Object.Queue.flush (.../fastboot-tryout/dist/fastboot/vendor.js:10523:11)
at Object.DeferredActionQueues.flush (.../fastboot-tryout/dist/fastboot/vendor.js:10331:17)
at Object.Backburner.end (.../fastboot-tryout/dist/fastboot/vendor.js:10686:25)
at [object Object]._onTimeout (.../fastboot-tryout/dist/fastboot/vendor.js:11252:18)
```

The real error is kind of "swallowed" and very very hard to find. What happens behind the scene is the following:

The error is kind of caught in a promise and the reject callback in `rsvp/-internal` is called. This happens in `initializePromise` with `reject(promise, e)` for more details see the screenshot of the stack trace. At this point the correct error is "caught"

![stacktrace](https://cloud.githubusercontent.com/assets/1695329/16393600/b4ca5df2-3cb1-11e6-82ae-e38a795edc93.jpg)

If you continue to step through the program there is going on a lot behind the scenes, like flushing the queues etc. At the end `fastboot/lib/result.js` calls the `_finalize` method and then `_finalizeMetadata`. `_finalizeMetadata` calls `instance.getURL()` and then for some reason getURL does not work because it is undefined. If there is no error during instance initializing then the stack trace looks almost the same and `instance.getURL()` works as expected.

The main problem with this issue is, that the stack trace to `_emberMetalProperty_get.get(...).getURL is not a function` is totally misleading. I digged around in all of the dependencies because the stack trace never pointed to my own source files and I was really lost. It was just coincidence that I had a break point in `rsvp/-internal` at the `reject` callback. I'm not sure if it is a bug but it makes getting fastboot to work really hard.

Steps to reproduce:

``` shell
mkdir fastboot-tryout
cd fastboot-tryout/
ember init
ember install ember-cli-fastboot
ember g instance-initializer make-fastboot-fail
vi app/instance-initializers/make-fastboot-fail.js
```

write something like the following into make-fastboot-fail.js

``` javascript
export function initialize(/* appInstance */) {
// appInstance.inject('route', 'foo', 'service:foo');
if(undef.makeItFail) {
return;
}
// DO SOMETHING
}

export default {
name: 'make-fastboot-fail',
initialize
};
```

Then execute the following commands:

``` shell
ember fastboot
curl http://localhost:3000/
```

After that you should see the exception from the beginning of my post. For more details I attached my package.json and bower.json

[package.txt](https://github.com/ember-fastboot/ember-cli-fastboot/files/335718/package.txt)
[bower.txt](https://github.com/ember-fastboot/ember-cli-fastboot/files/335719/bower.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.