jeff.hykin
jeff.hykin11mo ago

Deno Repl Programmatically

Python has a really nice not-well-known tool for creating a repl at any point in the code (kinda like a debugger but without any need for all the debugging setup). For example,
def somethin():
func = two_hour_long_computation_with_hard_to_serialze_output()
try:
a = untested_code_1(func)
b = untested_code_2(func)
c = untested_code_3(func)
except Exception as error:

#### important bit: creates a repl ####
import code; code.interact(local={**globals(),**locals()})
#### important bit ^ ####

save_results(a,b,c)
def somethin():
func = two_hour_long_computation_with_hard_to_serialze_output()
try:
a = untested_code_1(func)
b = untested_code_2(func)
c = untested_code_3(func)
except Exception as error:

#### important bit: creates a repl ####
import code; code.interact(local={**globals(),**locals()})
#### important bit ^ ####

save_results(a,b,c)
I then get a repl where I can poke around with the a, b, error vars, fix them and when I exit the repl it resumes execution (saving the output to disk so that I don't have to wait another 2 hours) Is there a way to do this in Deno? e.g. some unstable/hidden Deno.repl() I know a hacky solution could be made in userland via eval, but I wanted to check and see if there was an existing way
6 Replies
ioB
ioB11mo ago
I am not aware of anything like this, though this could be an interesting feature.
NeTT
NeTT11mo ago
Rather than "hacky", I'd say eval would be the proper way to use it.
mmastrac
mmastrac11mo ago
It's not ideal, but you can connect devtools to your running process and insert debugger where it needs to break. The console will work like a repl. I like the idea, however!
jeff.hykin
jeff.hykin11mo ago
It's hacky cause it won't have auto complete, syntax highlighting, "oh you didn't close a bracket => I'll allow multiline input", etc It could all be added with enough effort and --unstable
NeTT
NeTT11mo ago
That's indeed true
exegete
exegete11mo ago
Ruby has something similar with binding.irb (and previously binding.pry). Drops you into a REPL with debugging commands (next line, step into, step over, etc). It is hands down the best debugging experience I've ever had.