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.

IndexOutOfRangeException in HandlebarsDotNet.PathStructure.PathResolver.ResolvePath for nested object path block expression

See original GitHub issue

Describe the bug

Trying to enumerate an array via a nested object path:

{{#bundles.styles.vendor}}{{this}}{{/bundles.styles.vendor}}

Results in an IndexOutOfRangeException exception.

Expected behavior:

I would expect the same result as when not using a nested path, i.e.

{{#arr}}....{/arr}}

Or, alternatively, if this is not supported: a clearer exception message.

Test to reproduce

var context = new
{
  bundles = new
  {
	  styles = new
	  {
		  vendor = new[] { "a", "b", "c" }
	  }
  },
  arr = new[] { "d", "e", "f"}
};

// Works: Output = "abc"
Handlebars.Compile("{{#each bundles.styles.vendor}}{{this}}{{/each}}")(context).Dump();

// Works: Output = "def"
Handlebars.Compile("{{#arr}}{{this}}{{/arr}}")(context).Dump();

// Fails: IndexOutOfRangeException in HandlebarsDotNet.PathStructure.PathResolver.ResolvePath
// On line #36: if (!TryResolveValue(pathInfo.IsVariable, context, pathChain[0], instance, out instance))
Handlebars.Compile("{{#bundles.styles.vendor}}{{this}}{{/bundles.styles.vendor}}")(context).Dump();```

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aslezakcommented, Sep 1, 2021

Will do as soon as I have some spare time, and yes, I noticed I can do continue; in the loop instead of prefiltering them.

1reaction
oformaniukcommented, Aug 27, 2021

@aslezak , it’s hard to tell without testing. I’d really appreciate if you can have a look closer.

nit: Try to avoid Linq as this is performance critical path. In this case the check can be placed inside of for that is right below the line you mentioned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handlebars.Net
IndexOutOfRangeException in HandlebarsDotNet.PathStructure.PathResolver.ResolvePath for nested ... Trying to enumerate an array via a nested object path:
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