Weekly blog post #4

Published: 06/28/2021

What are you working on?

This week I kept working on the console that shows outputs and errors on screen (inside the iframe output) and I have finished it. I made two approaches:

  1. Overriding the console.error, console.debug, console.info and console.log javascript methods, only when they are called inside the iframe. I made sure that these new methods keep logging on the browser console but also display the message on a pre tag inside the iframe. Here is the PR for this approach.
  2. Redirecting sys.stderr and sys.stdout. Similar to the first solution, I redirected these two Python methods so they show the errors and the print() outputs on a pre tag inside the iframe as well. To catch the errors I used a try except with a exec() function inside, that runs the program captured in the text area. Here is the PR for this approach.

On both approaches I used the highlight.js library when there is an error to color key words.

My mentors are reviewing these two approaches to see which one is better. They were the ones that recommended a second approach on the first place because overriding console.log does not look like a good idea.

Once this gets merged, I would finish my first milestone. And start working on the second one.

What have you struggled with?

I struggled finding the second approach. Before I got to what I have now, I tried a lot of other alternatives but those were not working. I submitted an issue logging what I tried. My last attempt was missing the try except sentence for it to work. I could solve it, but I did struggle finding the solution.

What solutions have you found?

I joined the Brython google group where other people were having similar issues to mine, and I received a lot of help there: :D