2006-01-09 01:34:23 -05:00
|
|
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
2006-05-15 00:03:55 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: arrays generic hashtables inspector io kernel
|
|
|
|
kernel-internals math namespaces parser prettyprint sequences
|
2006-05-25 23:25:00 -04:00
|
|
|
sequences-internals strings styles vectors words ;
|
|
|
|
IN: errors
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-09-27 00:24:42 -04:00
|
|
|
SYMBOL: error
|
|
|
|
SYMBOL: error-continuation
|
2006-05-24 04:29:25 -04:00
|
|
|
SYMBOL: restarts
|
2005-09-27 00:24:42 -04:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: expired-error. ( obj -- )
|
2006-05-15 00:03:55 -04:00
|
|
|
"Object did not survive image save/load: " write third . ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: undefined-word-error. ( obj -- )
|
2006-05-15 00:03:55 -04:00
|
|
|
"Undefined word: " write third . ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-22 20:09:46 -04:00
|
|
|
: io-error. ( error -- )
|
2006-05-15 00:03:55 -04:00
|
|
|
"I/O error: " write third print ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: type-check-error. ( list -- )
|
2004-11-25 21:51:47 -05:00
|
|
|
"Type check error" print
|
2006-05-15 00:03:55 -04:00
|
|
|
"Object: " write dup fourth short.
|
|
|
|
"Object type: " write dup fourth class .
|
|
|
|
"Expected type: " write third type>class . ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: signal-error. ( obj -- )
|
2006-05-15 00:03:55 -04:00
|
|
|
"Operating system signal " write third . ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: negative-array-size-error. ( obj -- )
|
2006-05-15 00:03:55 -04:00
|
|
|
"Cannot allocate array with negative size " write third . ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: c-string-error. ( obj -- )
|
2006-05-15 00:03:55 -04:00
|
|
|
"Cannot convert to C string: " write third . ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: ffi-error. ( obj -- )
|
2006-05-15 00:03:55 -04:00
|
|
|
"FFI: " write third print ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: heap-scan-error. ( obj -- )
|
2005-04-25 03:33:33 -04:00
|
|
|
"Cannot do next-object outside begin/end-scan" print drop ;
|
2005-02-17 21:19:27 -05:00
|
|
|
|
2005-08-15 15:34:00 -04:00
|
|
|
: undefined-symbol-error. ( obj -- )
|
|
|
|
"The image refers to a library or symbol that was not found"
|
|
|
|
" at load time" append print drop ;
|
|
|
|
|
2005-09-20 20:18:01 -04:00
|
|
|
: user-interrupt. ( obj -- )
|
|
|
|
"User interrupt" print drop ;
|
|
|
|
|
2006-05-15 00:03:55 -04:00
|
|
|
: stack-underflow. ( obj name -- )
|
|
|
|
write " stack underflow" print drop ;
|
2006-02-07 17:29:36 -05:00
|
|
|
|
2006-05-15 00:03:55 -04:00
|
|
|
: stack-overflow. ( obj name -- )
|
|
|
|
write " stack overflow" print drop ;
|
2006-02-07 17:29:36 -05:00
|
|
|
|
2006-02-19 22:08:08 -05:00
|
|
|
! Hook for library/cocoa/
|
|
|
|
DEFER: objc-error. ( alien -- )
|
|
|
|
|
2006-05-15 00:03:55 -04:00
|
|
|
PREDICATE: array kernel-error ( obj -- ? )
|
|
|
|
dup first kernel-error eq? swap second 0 18 between? and ;
|
2004-12-25 21:28:47 -05:00
|
|
|
|
|
|
|
M: kernel-error error. ( error -- )
|
2005-03-25 21:43:06 -05:00
|
|
|
#! Kernel errors are indexed by integers.
|
2006-05-15 00:03:55 -04:00
|
|
|
dup second {
|
2005-09-22 21:01:55 -04:00
|
|
|
[ expired-error. ]
|
|
|
|
[ io-error. ]
|
|
|
|
[ undefined-word-error. ]
|
|
|
|
[ type-check-error. ]
|
|
|
|
[ signal-error. ]
|
|
|
|
[ negative-array-size-error. ]
|
|
|
|
[ c-string-error. ]
|
|
|
|
[ ffi-error. ]
|
|
|
|
[ heap-scan-error. ]
|
|
|
|
[ undefined-symbol-error. ]
|
|
|
|
[ user-interrupt. ]
|
2006-05-15 00:03:55 -04:00
|
|
|
[ "Data" stack-underflow. ]
|
|
|
|
[ "Data" stack-overflow. ]
|
|
|
|
[ "Retain" stack-underflow. ]
|
|
|
|
[ "Retain" stack-overflow. ]
|
|
|
|
[ "Call" stack-underflow. ]
|
|
|
|
[ "Call" stack-overflow. ]
|
2006-02-19 22:08:08 -05:00
|
|
|
[ objc-error. ]
|
2005-10-29 23:25:38 -04:00
|
|
|
} dispatch ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2006-05-05 01:59:39 -04:00
|
|
|
M: no-method summary
|
2006-07-23 21:38:58 -04:00
|
|
|
drop "No suitable method" ;
|
2006-05-05 01:59:39 -04:00
|
|
|
|
|
|
|
M: no-method error. ( error -- )
|
|
|
|
"Generic word " write
|
|
|
|
dup no-method-generic pprint
|
|
|
|
" does not define a method for the " write
|
|
|
|
dup no-method-object class pprint
|
|
|
|
" class." print
|
|
|
|
"Allowed classes: " write dup no-method-generic order .
|
|
|
|
"Dispatching on object: " write no-method-object short. ;
|
2004-12-25 21:28:47 -05:00
|
|
|
|
2006-07-23 21:38:58 -04:00
|
|
|
M: no-math-method summary
|
|
|
|
drop "No suitable arithmetic method" ;
|
2005-08-15 03:25:39 -04:00
|
|
|
|
2005-04-10 18:58:30 -04:00
|
|
|
: parse-dump ( error -- )
|
2005-05-19 15:16:25 -04:00
|
|
|
"Parsing " write
|
|
|
|
dup parse-error-file [ "<interactive>" ] unless* write
|
|
|
|
":" write
|
2005-08-21 20:50:14 -04:00
|
|
|
dup parse-error-line [ 1 ] unless* number>string print
|
2005-04-10 18:58:30 -04:00
|
|
|
|
2005-09-24 15:21:17 -04:00
|
|
|
dup parse-error-text dup string? [ print ] [ drop ] if
|
2005-04-10 18:58:30 -04:00
|
|
|
|
2005-12-24 18:29:31 -05:00
|
|
|
parse-error-col [ 0 ] unless*
|
|
|
|
CHAR: \s <string> write "^" print ;
|
2005-04-10 18:58:30 -04:00
|
|
|
|
|
|
|
M: parse-error error. ( error -- )
|
|
|
|
dup parse-dump delegate error. ;
|
|
|
|
|
2006-01-09 01:34:23 -05:00
|
|
|
M: bounds-error summary drop "Sequence index out of bounds" ;
|
2005-07-30 22:14:34 -04:00
|
|
|
|
2006-05-24 04:29:25 -04:00
|
|
|
M: condition error. delegate error. ;
|
|
|
|
|
2006-01-09 01:34:23 -05:00
|
|
|
M: tuple error. ( error -- ) describe ;
|
2004-12-25 21:28:47 -05:00
|
|
|
|
2006-07-28 00:50:09 -04:00
|
|
|
M: string error. ( error -- ) print ;
|
|
|
|
|
2005-03-25 21:43:06 -05:00
|
|
|
M: object error. ( error -- ) . ;
|
2004-07-18 22:18:41 -04:00
|
|
|
|
2005-09-27 00:24:42 -04:00
|
|
|
: :s ( -- ) error-continuation get continuation-data stack. ;
|
|
|
|
|
2006-05-14 23:09:47 -04:00
|
|
|
: :r ( -- ) error-continuation get continuation-retain stack. ;
|
|
|
|
|
2006-05-18 22:07:00 -04:00
|
|
|
: :c ( -- ) error-continuation get continuation-call callstack. ;
|
2004-11-15 22:47:19 -05:00
|
|
|
|
2005-09-27 00:24:42 -04:00
|
|
|
: :get ( var -- value )
|
2005-11-12 00:37:24 -05:00
|
|
|
error-continuation get continuation-name hash-stack ;
|
2004-11-20 16:57:01 -05:00
|
|
|
|
2006-05-24 04:29:25 -04:00
|
|
|
: :res ( n -- ) restarts get nth first3 continue-with ;
|
|
|
|
|
2006-05-25 23:25:00 -04:00
|
|
|
: (debug-help) ( string quot -- )
|
2006-06-14 01:47:28 -04:00
|
|
|
<input> write-object terpri ;
|
2006-05-25 23:25:00 -04:00
|
|
|
|
|
|
|
: restart. ( restart n -- )
|
|
|
|
[ [ # " :res " % first % ] "" make ] keep
|
|
|
|
[ :res ] curry (debug-help) ;
|
|
|
|
|
2006-05-24 04:29:25 -04:00
|
|
|
: restarts. ( -- )
|
|
|
|
restarts get dup empty? [
|
|
|
|
drop
|
|
|
|
] [
|
2006-05-25 23:25:00 -04:00
|
|
|
terpri
|
2006-05-24 04:29:25 -04:00
|
|
|
"The following restarts are available:" print
|
2006-05-25 23:25:00 -04:00
|
|
|
terpri
|
|
|
|
dup length [ restart. ] 2each
|
2006-05-24 04:29:25 -04:00
|
|
|
] if ;
|
|
|
|
|
2004-12-25 21:28:47 -05:00
|
|
|
: debug-help ( -- )
|
2006-05-25 23:25:00 -04:00
|
|
|
terpri
|
|
|
|
"Debugger commands:" print
|
|
|
|
terpri
|
|
|
|
":s data stack at exception time" [ :s ] (debug-help)
|
|
|
|
":r retain stack at exception time" [ :r ] (debug-help)
|
|
|
|
":c call stack at exception time" [ :c ] (debug-help)
|
2006-01-23 21:03:22 -05:00
|
|
|
":get ( var -- value ) accesses variables at time of error" print
|
2005-12-16 21:12:35 -05:00
|
|
|
flush ;
|
2004-12-25 21:28:47 -05:00
|
|
|
|
|
|
|
: print-error ( error -- )
|
2006-05-25 23:25:00 -04:00
|
|
|
[
|
|
|
|
dup error.
|
|
|
|
restarts.
|
|
|
|
debug-help
|
|
|
|
] [
|
|
|
|
"Error in print-error!" print
|
|
|
|
] recover drop ;
|
2004-11-23 22:20:23 -05:00
|
|
|
|
2006-05-25 23:25:00 -04:00
|
|
|
: try ( quot -- ) [ print-error ] recover ;
|
2004-11-26 22:23:57 -05:00
|
|
|
|
2005-09-27 00:24:42 -04:00
|
|
|
: save-error ( error continuation -- )
|
2006-05-24 04:29:25 -04:00
|
|
|
error-continuation set-global
|
|
|
|
dup error set-global
|
|
|
|
compute-restarts restarts set-global ;
|
2005-03-21 14:39:46 -05:00
|
|
|
|
2005-09-28 20:09:10 -04:00
|
|
|
: error-handler ( error -- )
|
|
|
|
dup continuation save-error rethrow ;
|
|
|
|
|
2004-11-26 22:23:57 -05:00
|
|
|
: init-error-handler ( -- )
|
2005-11-12 00:37:24 -05:00
|
|
|
V{ } clone set-catchstack
|
2005-03-21 14:39:46 -05:00
|
|
|
( kernel calls on error )
|
2005-09-28 20:09:10 -04:00
|
|
|
[ error-handler ] 5 setenv
|
2004-12-26 01:42:09 -05:00
|
|
|
kernel-error 12 setenv ;
|