New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when you return a single string to {{#each}} #722

Closed
EvHaus opened this Issue Feb 22, 2013 · 6 comments

Comments

Projects
None yet
4 participants
@EvHaus

EvHaus commented Feb 22, 2013

If you return a string from a helper that is used in {{#each}}, we should print a clear error instead of something about "Cannot use 'in' operator".

(original report follows, but @glasser thinks that was just a version skew:)

Meteor.users.find({}).observeChanges({...} fails with:

TypeError: Object [object Object] has no method 'observeChanges'.

observe() seems to work just fine though.

@awatson1978

This comment has been minimized.

Contributor

awatson1978 commented Feb 22, 2013

True dat. I was getting the following error

Uncaught TypeError: Cannot use 'in' operator to search for 'observeChanges' in List of collaborators not available right now.

When running this code:

Template.userCardTemplate.user_collaborators = function () {
    if(Meteor.user()){
        if(Meteor.user().profile){
            return Meteor.user().profile.collaborators;
        }
    }else{
        return "List of collaborators not available right now.";
    }
};

It's not the best code ever, but it was working fine prior to observeChanges. In particular, observeChanges doesn't seem to like empty arrays or empty fields. It doesn't even like it if you reference them. Which seems to suggest it's not a problem with the results (or lack thereof), but with the parsing of the location itself.

Somehow, observing partial updates has resulted in an inability to parse objects with null values, missing values, or empty arrays. Or something like that.

@glasser

This comment has been minimized.

Member

glasser commented Feb 27, 2013

@globexdesigns Are you sure you are using Meteor 0.5.7? observeChanges is new in 0.5.7. Also, is this code on the server or the client?

@awatson1978 That looks like a different issue. Let me look into that...

@glasser

This comment has been minimized.

Member

glasser commented Feb 27, 2013

@awatson1978 Is the full context that you are doing a {{#each user_collaborators}}? I see where this error comes from, and it could probably be avoided by changing the code slightly... but (a) It looks like pre-0.5.7 should have had the same bug and (b) if you're returning a single string from something that you are #eaching over, it's not going to work well anyway. Can you show a full example of this (eg, a cloneable project)?

@awatson1978

This comment has been minimized.

Contributor

awatson1978 commented Feb 27, 2013

Yeah, it was within a {{#each user_collaborators}} block. I found a workaround by simply wrapping the clause in a try/catch clause, like so:

Template.userCardTemplate.user_collaborators = function () {
      try{
          if(Meteor.user().profile){
              return Meteor.user().profile.collaborators;
          }else{
              return "List of carewatch members not available right now.";
          }
      }catch(err){
          log_event(err, LogLevel.Error);
      }
  };

Yeah, come to think of it, that "List of carewatch members not available right now." string is a leftover from when I was testing getting a single collaborator working, and it now never shows up in the app! I should remove it! :p

As for the example... um... my schedule is pretty packed till Sunday with an offline roadtrip to Chicago. I'll see if I can get it done later today before the trip though....

@glasser

This comment has been minimized.

Member

glasser commented Mar 4, 2013

I've updated the issue to be about the string/{{#each}} issue (@globexdesigns, do let me know if you're still seeing your original issue). We should improve this error message, or will happily take a pull request to do so.

@iMagdy

This comment has been minimized.

iMagdy commented Jun 24, 2013

It took me a while to sort this out this issue, I had a condition check if the collection return results do this, if is empty return string, and obviously this is my bad since there's nothing called looping/eaching a string :D but true, the error message wasn't clear enough, and it would have been super hard to find it out without this thread!

@avital avital closed this in 7e8c2f9 Sep 24, 2013

avital added a commit that referenced this issue Sep 24, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment