Skip to content

Conversation

@gigasquid
Copy link
Contributor

Some basic functions for dealing with exceptions.

This adds a way to print and turn stack traces into seqs.

It adds two functions pst and trace

pst works on either an exception or if no arg is given the last exception thrown as *e. It will simply print the stack trace.

user => (/ 0 0)

; orig stack trace omitted

user => (pst)
in <unknown> at 1:1
(/ 0 0)
^
in pixie function 

in /Users/cmeier/workspace/misc/pixie/pixie/stdlib.pxi at 511:10
  ([x y] (-div x y))
         ^
in internal function _div

RuntimeException: Divide by zero

nil

user => (pst *e)
in <unknown> at 1:1
(/ 0 0)
^
in pixie function 

in /Users/cmeier/workspace/misc/pixie/pixie/stdlib.pxi at 511:10
  ([x y] (-div x y))
         ^
in internal function _div

RuntimeException: Divide by zero

nil

trace also works on either an exception or if none is given, the last bound to *e. It turns the trace into a seq, which someone can do further processing and inspection on.

user => (trace)
("Divide by zero" "in internal function _div\n" "in /Users/cmeier/workspace/misc/pixie/pixie/stdlib.pxi at 511:10\n  ([x y] (-div x y))\n         ^" "in pixie function \n" "in <unknown> at 1:1\n(/ 0 0)\n^")

user => (trace *e)
("Divide by zero" "in internal function _div\n" "in /Users/cmeier/workspace/misc/pixie/pixie/stdlib.pxi at 511:10\n  ([x y] (-div x y))\n         ^" "in pixie function \n" "in <unknown> at 1:1\n(/ 0 0)\n^")

seq was also extended to Runtime Exceptions.

@halgari Let me know if this is what you were thinking of..

pixie/stdlib.pxi Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be the var e instead of *e?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes indeed - nice catch :)

@halgari
Copy link
Member

halgari commented Feb 24, 2015

BTW, this build failed due to BitBucket being down. Not your fault.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, but I'd also like a bit more detail. Can we add a method to each of the ErrorInfo types (found here: https://github.com/pixie-lang/pixie/blob/master/pixie/vm/object.py#L157), that construct a map or something for each frame? As it stands we'd need to parse the strings if we want anything useful out of the trace. So you could probably just clone each __repr__ method and construct a map instead of a string. So polymorphic code info would look something like {:type :polymorphic :name "-count" :type <type int>}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, keep the patches coming, it's great to see this stuff moving forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 ✨

@gigasquid
Copy link
Contributor Author

Here is my next pass of exception trace maps:

Pixie 0.1 - Interactive REPL
(darwin_x86_64, clang)
:exit-repl or Ctrl-D to quit
----------------------------
user => (/ 0 0)
Error:  in <unknown> at 1:1
(/ 0 0)
^
in pixie function 

in /Users/cmeier/workspace/misc/pixie/pixie/stdlib.pxi at 511:10
  ([x y] (-div x y))
         ^
in internal function _div

RuntimeException: Divide by zero

user => (trace)
({:data "Divide by zero", :type "runtime"} {:type "native", :name "_div"} {:line_number "511", :line "  ([x y] (-div x y))", :column_number "10", :type "interpreter", :file "/Users/cmeier/workspace/misc/pixie/pixie/stdlib.pxi"} {:type "pixie", :name ""} {:line_number "1", :line "(/ 0 0)", :column_number "1", :type "interpreter", :file "<unknown>"})

feedback welcome as always

@heyLu
Copy link
Member

heyLu commented Feb 25, 2015

That looks pretty good! ✨

Why did you make :line_number and :column_number strings? I'd imagine it would be more convenient to get numbers back.

(And even more nitpicky: Could you change the names to :line-number and :column-number or even :line and :column? Dashes seem to be the usual Clojure style for keywords...)

@gigasquid
Copy link
Contributor Author

Thanks - great feedback. I will make the changes. I am still struggling working with python/rpython, so I lose track of the little stuff sometimes while just trying to get it to compile and build :)

pixie/stdlib.pxi Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can already do this with (print (str e)), then you don't need a separate ex-pr or alternatively implement it as just (print (str e)).

(Sorry that this is so late.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool I will update in the pull request

@gigasquid
Copy link
Contributor Author

Cool - implemented the changes and learned quite a bit about rpython in the process :)

Here is the latest:

  • changed the line and column numbers to ints
  • changed the types to keywords
  • changed pst to use (pr (str e))
user => (/ 0 0)
Error:  in <unknown> at 1:1
(/ 0 0)
^
in pixie function 

in /Users/cmeier/workspace/misc/pixie/pixie/stdlib.pxi at 511:10
  ([x y] (-div x y))
         ^
in internal function _div

RuntimeException: Divide by zero

user => (trace)
({:data "Divide by zero", :type :runtime} {:type :native, :name "_div"} {:line-number 511, :line "  ([x y] (-div x y))", :column-number 10, :type :interpreter, :file "/Users/cmeier/workspace/misc/pixie/pixie/stdlib.pxi"} {:type :pixie, :name ""} {:line-number 1, :line "(/ 0 0)", :column-number 1, :type :interpreter, :file "<unknown>"})

heyLu added a commit that referenced this pull request Feb 26, 2015
@heyLu heyLu merged commit 0b1f7e1 into pixie-lang:master Feb 26, 2015
@heyLu
Copy link
Member

heyLu commented Feb 26, 2015

Thanks a lot! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants