question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create better error for missing decorated getters

See original GitHub issue

In the case of using the decorate syntax (in an environment where decorators aren’t enabled), there is a really confusing error message.

For example, in the documentation on how to not use decorators, you have this example:

class Timer {
  start = Date.now();
  current = Date.now();

  get elapsedTime() {
    return this.current - this.start + "milliseconds";
  }

  tick() {
    this.current = Date.now();
  }
}
decorate(Timer, {
  start: observable,
  current: observable,
  elapsedTime: computed,
  tick: action
});

If you delete the get elapsedTime(){ function, you get this error:

Uncaught TypeError: Cannot read property 'get' of undefined
    at Object.propertyCreator (mobx.module.js:596)
    at initializeInstance$$1 (mobx.module.js:373)
    at MobxStore.set [as activeFile] (mobx.module.js:358)
    at new MobxStore (MobxStore.js:33)

The problem is that the elapsedTime: computed property doesn’t get deleted with the function, which is easy to do when they aren’t co-located (without decorators). This keeps happening to me and I’ve memorized the error, but the first couple times where hard to track down. It seems like there is no intentional error checking - it just errors down the stack at instantiation of the class.

I think it should error (give the dev a chance to clean up cruft) but give them more information why it’s throwing an error.

Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:29 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
andreipfeiffercommented, Aug 7, 2019

If you get the property is not declared configurable error when using Jest spyOn on mobx @computed properties, you can add this:

import { configure } from "mobx";
configure({ computedConfigurable: true });

Thanks @wlindner 😉

PS: it’s documented here https://mobx.js.org/refguide/api.html

6reactions
mweststratecommented, Feb 14, 2019

@zetoke, I don’t like settings in at all in generally, but it might actually be a nice idea in this case, to have it a ‘test only’ setting. Something like mobx.configure({ enableStubbing: true }) ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Create better error for missing decorated getters -
In the case of using the decorate syntax (in an environment where decorators aren't enabled), there is a really confusing error message.
Read more >
Is there a way to modify property values by getters and setters ...
Is there a way to modify property values by getters/setters on model? or Is there any other alternative? Another consideration is that Realm ......
Read more >
Use Getters and Setters to Modify Data - Salesforce Developers
It's a best practice to annotate the getter. To hold the property value inside the getter and setter, use a field. This example...
Read more >
Error codes - CKEditor 5 Documentation
Error codes. CKEditor 5 Framework logs errors and warnings to the console. The following list contains more detailed descriptions of those issues.
Read more >
Documentation - Decorators - TypeScript
Decorators provide a way to add both annotations and a meta-programming ... that will be called at runtime with information about the decorated...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found