unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-user@gnu.org
Subject: Re: reporting 'system-error informatively
Date: 21 Oct 2002 19:55:57 +0100	[thread overview]
Message-ID: <m3y98rbozm.fsf@laruns.ossau.uklinux.net> (raw)
In-Reply-To: <873cqzx33b.fsf@zagadka.ping.de>

>>>>> "Marius" == Marius Vollmer <mvo@zagadka.ping.de> writes:

    >> Is there any way to get the arguments themselves, as plain Scheme
    >> values instead of text?

    Marius> Probably.  Messing around with the 'stack' data structure is probably
    Marius> the right thing.  Sorry, I can't say more.  (But others might.)

Assuming that `the-last-stack' has caught the error that you want to
look at, you can get the stack object by

(define s (fluid-ref the-last-stack))

and then the innermost stack frame by

(define f (stack-ref s 0))

Now, a frame can be either an application or an evaluation, and you'll
often find that the innermost frame is an application, with the one
just higher being an evaluation, e.g.

innermost: [string-length 4]
1 outer: (string-length 4)

(frame-procedure? f) tells you whether the frame is an application.
If it is, (frame-procedure f) returns the procedure and
(frame-arguments f) returns the already evaluated args.  If it isn't,
(frame-source f) -- i.e. the frame is an evaluation -- returns the
expression that was being evaluated, which is all you can get.

So (untested as usual) ...

(define (last-error->proc+args)
  (let* ((stack (fluid-ref the-last-stack))
         (stacklen (stack-length stack)))
    (let loop ((index 0))
      (if (< index stacklen)
          (let ((frame (stack-ref stack index)))
            (if (frame-procedure? frame)
                (values (frame-procedure frame)
                        (frame-arguments frame))
                (loop (+ index 1))))
          #f))))

If `the-last-stack' hasn't captured the error that you want, you can
capture it for yourself using `lazy-catch' and `make-stack':

(define my-stack #f)

(define (saving-error-to-my-stack proc)
  (define (lazy-handler key . args)
    (set! my-stack (make-stack #t lazy-handler))
    (apply throw key args))
  (lazy-catch #t
    proc
    lazy-handler))

Notes - (i) the `lazy-handler' in the `make-stack' call tells
make-stack to return a stack object whose innermost frame is just
outside the call into lazy-handler; (ii) the `#t' in the make-stack
call means "here"; (iii) you must always rethrow from a lazy handler,
hence the `(apply throw ...)' line.

This should of course be in the manual.  If anyone feels like working
this into an appropriate patch, I'd appreciate it.

        Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


      parent reply	other threads:[~2002-10-21 18:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-19 21:18 reporting 'system-error informatively Paul Jarc
2002-10-20 21:38 ` Marius Vollmer
2002-10-20 23:02   ` Daniel Skarda
2002-10-21 14:46     ` Marius Vollmer
2002-10-21  6:13   ` Paul Jarc
2002-10-21 14:45     ` Marius Vollmer
2002-10-21 18:36       ` Paul Jarc
2002-10-21 18:55       ` Neil Jerram [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3y98rbozm.fsf@laruns.ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).