emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.45k stars 4.21k forks source link

[Bug] "Attempted to create a log for a path reference" hiding real error #19180

Open wagenet opened 3 years ago

wagenet commented 3 years ago

🐞 Describe the Bug

While running tests I encountered this message:

testem.js:967 Error: BUG: Attempted to create a log for a path reference, but no node exist for that reference
    at expect (util.js:159)
    at DebugRenderTree.logRenderStackForPath (index.js:4492)
    at EmberEnvironmentDelegate.getTemplatePathDebugContext (index.js:5176)
    at EnvironmentImpl.getTemplatePathDebugContext (runtime.js:1849)
    at fn (index.js:5984)
    at HelperRootReference.callback [as fn] (index.js:6005)
    at reference.js:231
    at runInAutotrackingTransaction (validator.js:83)
    at track (validator.js:690)
    at HelperRootReference.compute (reference.js:230)

🔬 Minimal Reproduction

https://codesandbox.io/s/nostalgic-einstein-jdsfm

😕 Actual Behavior

Upon further investigation the error is stems from an assert in the fn helper. In this case, our test did not pass the expected function which triggered this bit of code:

  if (DEBUG && typeof callbackRef[INVOKE] !== 'function') {
    let callback = callbackRef.value();
    assert(`You must pass a function as the \`fn\` helpers first argument, you passed ${callback === null ? 'null' : typeof callback}. ${env.getTemplatePathDebugContext(callbackRef)}`, typeof callback === 'function');
  }

Unfortunately, the effort to get more debug information is what causes the error, hiding the real error in the process. Ultimately, the error is from logRenderStackForPath which has the following code:

let node = expect(this.pathNodes.get(pathRef), 'BUG: Attempted to create a log for a path reference, but no node exist for that reference');

pathRef is callbackRef from the original assert and this.pathNodes.get(pathRef) returns undefined.

🤔 Expected Behavior

There are two issues I see here 1) maybe this shouldn't be returning undefined and 2) even if there is an error in getting debug information, we should catch it so it doesn't hide the real error.

🌍 Environment

wagenet commented 3 years ago

I have verified that this issue is introduced in Ember 3.19. Before that it gives an error about how it must be a function. I'm guessing that additional debugging was added for 3.19, which caused the issue.

KalachevDev commented 3 years ago

Hey! I've seen the same issue with glimmer component. I accidentally didn't pass callback to fn helper and instead of descriptive message about missing callback I've got: Attempted to create a log for a path reference

mcfiredrill commented 3 years ago

Hey! I've seen the same issue with glimmer component. I accidentally didn't pass callback to fn helper and instead of descriptive message about missing callback I've got: Attempted to create a log for a path reference

Same issue, a descriptive error message would be nice here.

rwjblue commented 3 years ago

I think we just landed a fix for this over in https://github.com/emberjs/ember.js/pull/19195. I'll be working on a series of backports / releases over the next day or two to get it released.

tracyalison11 commented 2 years ago

I recently received the same error because I did not include mock actions in my test setup that the component was expecting. This made it very difficult to debug. Any insight into why this error gets thrown with a message that's unrelated to the issue?