whole-tale / dashboard

Whole Tale Dashboard
http://wholetale.org
MIT License
7 stars 2 forks source link

View logs not working #602

Closed craig-willis closed 4 years ago

craig-willis commented 4 years ago

Build: v0.9rc2-2-gc9c4b5e tested on staging

Problem: During image build, view logs fails with ReferenceError: jobId is not defined

To repeat:

Expected behavior:

Actual behavior:

Screen Shot 2020-02-27 at 12 01 01 PM
Xarthisius commented 4 years ago

Looking at the js code:

https://github.com/whole-tale/dashboard/blob/cd22d3432b5746e9a7a766cd52131d2d8c8cbbeb/app/components/ui/notification-stream/component.js#L45-L50

and how that code is executed, jobId never makes it outside the if statement. I had var jobId there initially, instead of let jobId, but I was suggested to change it https://github.com/whole-tale/dashboard/pull/592#discussion_r380808841 @bodom0015 is there something I'm doing wrong there?

bodom0015 commented 4 years ago

@Xarthisius kind of moot now since you got it working, but for completeness' sake:

Yes, this was the exact same problem as https://github.com/whole-tale/dashboard/pull/595#discussion_r380838395 - sorry that I missed it during the first review cycle

You can't declare a variable in an if statement and expect to use it outside of the if scope. This is true for any programming language that provides block-level scoping (Python does not). Changing to let is what caused it to actually throw an error when the variable goes out of scope, whereas var would have just tried to guess what you were trying to do.

You instead have to declare it outside the if block (at the scope which you plan on using it), and assign it a value inside the if block.