Changeset 6642


Ignore:
Timestamp:
Jun 3, 2007, 2:40:42 AM (17 years ago)
Author:
Gary Byers
Message:

Define and use STREAM-ERROR-CONTEXT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ide-1.0/ccl/level-1/l1-error-system.lisp

    r6273 r6642  
    337337(define-condition stream-error (error)
    338338  ((stream :initarg :stream :reader stream-error-stream)))
     339
     340(defun stream-error-context (condition)
     341  (let* ((stream (stream-error-stream condition)))
     342    (with-output-to-string (s)
     343       (format s "on steam ~s" stream)
     344       (let* ((pos (ignore-errors (stream-position stream))))
     345         (when pos
     346           (format s ", near position ~d" pos)))
     347       (let* ((surrounding (stream-surrounding-characters stream)))
     348         (when surrounding
     349           (format s ", within ~s" surrounding))))))
     350
    339351(define-condition parse-error (error) ())
    340352(define-condition parse-integer-not-integer-string (parse-error)
     
    346358(define-condition end-of-file (stream-error) ()
    347359  (:report (lambda (c s)
    348              (format s "Unexpected end of file on ~s" (stream-error-stream c)))))
     360             (format s "Unexpected end of file ~s" (stream-error-context c)))))
    349361(define-condition impossible-number (reader-error)
    350362  ((token :initarg :token :reader impossible-number-token)
    351363   (condition :initarg :condition :reader impossible-number-condition))
    352364  (:report (lambda (c s)
    353              (format s "Condition of type ~s raised ~&while trying to parse numeric token ~s ~&on ~s"
     365             (format s "Condition of type ~s raised ~&while trying to parse numeric token ~s ~&~s"
    354366                     (type-of (impossible-number-condition c))
    355367                     (impossible-number-token c)
    356                      (stream-error-stream c)))))
     368                     (stream-error-context c)))))
    357369
    358370
     
    360372(define-condition simple-stream-error (stream-error simple-condition) ()
    361373  (:report (lambda (c s)
    362              (format s "Error on ~s : ~&~a" (stream-error-stream c)
     374             (format s "Error ~s : ~&~a" (stream-error-context c)
    363375                     (apply #'format
    364376                            nil
     
    367379
    368380
    369 (define-condition modify-read-only-buffer (error) ()
    370   (:report (lambda (c s)
    371              (declare (ignore c))
    372              (format s "Cannot modify a read-only buffer"))))
     381
    373382
    374383(define-condition file-error (error)
Note: See TracChangeset for help on using the changeset viewer.