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.

How to reference all instances created in a @loop statement?

See original GitHub issue

I’m trying to create a test-script that calls a (POST) endpoint multiple times and then uses the results of each call in subsequence calls.

This is what I’ve tried:

# @name uuid
# @loop for 2
GET https://httpbin.org/uuid

###

# @ref uuid
# @loop for item of uuidList
POST https://httpbin.org/post
Content-Type: application/json

{
    "item": "{{item.uuid}}"
}

Unfortunately this fails with:

ERROR: ReferenceError - uuidList is not defined
ReferenceError: uuidList is not defined
	at Object.<anonymous> (demo.http:9:20)
	at t9 ($HOME/.vscode/extensions/anweber.vscode-httpyac-5.4.1/dist/extension.js:151:40879)
	at Object.nSe [as evalExpression] ($HOME/.vscode/extensions/anweber.vscode-httpyac-5.4.1/dist/extension.js:151:41428)
	at bIt.iterateForOfLoop ($HOME/.vscode/extensions/anweber.vscode-httpyac-5.4.1/dist/extension.js:150:45758)
	at iterateForOfLoop.next (<anonymous>)
	at bIt.iterate ($HOME/.vscode/extensions/anweber.vscode-httpyac-5.4.1/dist/extension.js:150:45540)
	at iterate.next (<anonymous>)
	at bIt.beforeLoop ($HOME/.vscode/extensions/anweber.vscode-httpyac-5.4.1/dist/extension.js:150:45010)
	at OW.<anonymous> ($HOME/.vscode/extensions/anweber.vscode-httpyac-5.4.1/dist/extension.js:1:4989)
	at Generator.next (<anonymous>)

I know that using the <variableName>List variable is an undocumented feature that I found while reviewing the code:

https://github.com/AnWeber/httpyac/blob/a6559fca27509aa35fd4427b4866ab496633cff9/src/plugins/core/metaData/loopMetaDataHandler.ts#L90

Is there maybe a better way of referencing all results of a @loop for n statement?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
AnWebercommented, May 28, 2022

With v5.4.2 the fix for the bugs is released. Thanks for reporting.

0reactions
JanAhrenscommented, May 30, 2022

Thanks for fixing this. I really appreciate it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create references to objects created in a loop?
Use an ArrayList: ArrayList<JButton> list=new ArrayList<>(); int numOfButtons = 10; for (int i = 0; i < numOfButtons; i++){ JButton jb=new ...
Read more >
Iteration statements -for, foreach, do, and while - Microsoft Learn
You can step to the next iteration in the loop using the continue statement. ... All the sections of the for statement are...
Read more >
Loops and iteration - JavaScript - MDN Web Docs
The for...of statement creates a loop Iterating over iterable objects (including Array , Map , Set , arguments object and so on), invoking...
Read more >
Terraform tips & tricks: loops, if-statements, and gotchas
The for_each expression allows you to loop over lists, sets, and maps to create (a) multiple copies of an entire resource, (b) multiple...
Read more >
For Loops, For...Of Loops and For...In Loops in JavaScript
All three expressions in the for loop are optional. For example, we can write the same for statement without the initialization expression ...
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