2005-02-10 15:14:20 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-04-02 00:56:00 -05:00
|
|
|
IN: errors
|
|
|
|
USING: generic kernel kernel-internals lists math namespaces
|
2005-08-21 20:50:14 -04:00
|
|
|
parser prettyprint sequences io strings vectors words ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: expired-error. ( obj -- )
|
2004-11-25 21:51:47 -05:00
|
|
|
"Object did not survive image save/load: " write . ;
|
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: undefined-word-error. ( obj -- )
|
2004-11-25 21:51:47 -05:00
|
|
|
"Undefined word: " write . ;
|
|
|
|
|
2005-04-22 20:09:46 -04:00
|
|
|
: io-error. ( error -- )
|
|
|
|
"I/O error: " write 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
|
2005-08-24 19:25:12 -04:00
|
|
|
uncons car dup "Object: " write short.
|
2005-08-21 14:40:12 -04:00
|
|
|
"Object type: " write class .
|
|
|
|
"Expected type: " write type>class . ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: float-format-error. ( list -- )
|
2004-11-25 21:51:47 -05:00
|
|
|
"Invalid floating point literal format: " write . ;
|
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: signal-error. ( obj -- )
|
2004-11-25 21:51:47 -05:00
|
|
|
"Operating system signal " write . ;
|
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: negative-array-size-error. ( obj -- )
|
2004-11-25 21:51:47 -05:00
|
|
|
"Cannot allocate array with negative size " write . ;
|
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: c-string-error. ( obj -- )
|
2004-11-25 21:51:47 -05:00
|
|
|
"Cannot convert to C string: " write . ;
|
|
|
|
|
2005-04-02 00:56:00 -05:00
|
|
|
: ffi-error. ( obj -- )
|
2004-11-25 21:51:47 -05:00
|
|
|
"FFI: " write print ;
|
|
|
|
|
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 ;
|
|
|
|
|
2004-12-25 21:28:47 -05:00
|
|
|
PREDICATE: cons kernel-error ( obj -- ? )
|
2005-09-22 21:01:55 -04:00
|
|
|
dup first kernel-error = swap second 0 11 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.
|
2005-09-22 21:01:55 -04:00
|
|
|
cdr uncons car swap @{
|
|
|
|
[ expired-error. ]
|
|
|
|
[ io-error. ]
|
|
|
|
[ undefined-word-error. ]
|
|
|
|
[ type-check-error. ]
|
|
|
|
[ float-format-error. ]
|
|
|
|
[ signal-error. ]
|
|
|
|
[ negative-array-size-error. ]
|
|
|
|
[ c-string-error. ]
|
|
|
|
[ ffi-error. ]
|
|
|
|
[ heap-scan-error. ]
|
|
|
|
[ undefined-symbol-error. ]
|
|
|
|
[ user-interrupt. ]
|
|
|
|
}@ dispatch ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-03-25 21:43:06 -05:00
|
|
|
M: no-method error. ( error -- )
|
2005-05-23 01:18:51 -04:00
|
|
|
"No suitable method." print
|
|
|
|
"Generic word: " write dup no-method-generic .
|
2005-08-24 19:25:12 -04:00
|
|
|
"Object: " write no-method-object short. ;
|
2004-12-25 21:28:47 -05:00
|
|
|
|
2005-08-15 03:25:39 -04:00
|
|
|
M: no-math-method error. ( error -- )
|
|
|
|
"No suitable arithmetic method." print
|
|
|
|
"Generic word: " write dup no-math-method-generic .
|
2005-08-24 19:25:12 -04:00
|
|
|
"Left operand: " write dup no-math-method-left short.
|
|
|
|
"Right operand: " write no-math-method-right short. ;
|
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
|
|
|
|
|
|
|
dup parse-error-text dup string? [ print ] [ drop ] ifte
|
|
|
|
|
2005-06-12 20:55:30 -04:00
|
|
|
parse-error-col [ 0 ] unless* CHAR: \s fill write "^" print ;
|
2005-04-10 18:58:30 -04:00
|
|
|
|
|
|
|
M: parse-error error. ( error -- )
|
|
|
|
dup parse-dump delegate error. ;
|
|
|
|
|
2005-07-30 22:14:34 -04:00
|
|
|
M: bounds-error error. ( error -- )
|
|
|
|
"Sequence index out of bounds" print
|
2005-08-24 19:25:12 -04:00
|
|
|
"Sequence: " write dup bounds-error-seq short.
|
2005-07-30 22:14:34 -04:00
|
|
|
"Minimum: 0" print
|
|
|
|
"Maximum: " write dup bounds-error-seq length .
|
|
|
|
"Requested: " write bounds-error-index . ;
|
|
|
|
|
2005-03-25 21:43:06 -05:00
|
|
|
M: string error. ( error -- ) print ;
|
2004-12-25 21:28:47 -05:00
|
|
|
|
2005-03-25 21:43:06 -05:00
|
|
|
M: object error. ( error -- ) . ;
|
2004-07-18 22:18:41 -04:00
|
|
|
|
2005-08-27 15:33:29 -04:00
|
|
|
: :s ( -- ) "error-datastack" get stack. ;
|
|
|
|
: :r ( -- ) "error-callstack" get stack. ;
|
2004-11-15 22:47:19 -05:00
|
|
|
|
2004-11-20 16:57:01 -05:00
|
|
|
: :get ( var -- value ) "error-namestack" get (get) ;
|
|
|
|
|
2004-12-25 21:28:47 -05:00
|
|
|
: debug-help ( -- )
|
2005-08-21 01:17:37 -04:00
|
|
|
":s :r show stacks at time of error." print
|
|
|
|
":get ( var -- value ) inspects the error namestack." print ;
|
2004-12-25 21:28:47 -05:00
|
|
|
|
2005-09-22 16:21:36 -04:00
|
|
|
: flush-error-handler ( -- )
|
2004-11-25 23:14:17 -05:00
|
|
|
#! Last resort.
|
2005-09-22 16:21:36 -04:00
|
|
|
[ "Error in default error handler!" print ] when ;
|
2004-11-25 23:14:17 -05:00
|
|
|
|
2004-12-25 21:28:47 -05:00
|
|
|
: print-error ( error -- )
|
2004-11-25 23:14:17 -05:00
|
|
|
#! Print the error.
|
2005-09-21 01:12:16 -04:00
|
|
|
[ dup error. ] catch nip flush-error-handler ;
|
2004-11-23 22:20:23 -05:00
|
|
|
|
2004-12-25 21:28:47 -05:00
|
|
|
: try ( quot -- )
|
2004-11-23 22:20:23 -05:00
|
|
|
#! Execute a quotation, and if it throws an error, print it
|
|
|
|
#! and return to the caller.
|
2005-09-21 01:12:16 -04:00
|
|
|
[ print-error debug-help ] recover ;
|
2004-11-26 22:23:57 -05:00
|
|
|
|
2005-03-21 14:39:46 -05:00
|
|
|
: save-error ( error ds rs ns cs -- )
|
|
|
|
#! Save the stacks and parser state for post-mortem
|
|
|
|
#! inspection after an error.
|
2005-03-25 21:43:06 -05:00
|
|
|
global [
|
|
|
|
"error-catchstack" set
|
|
|
|
"error-namestack" set
|
|
|
|
"error-callstack" set
|
|
|
|
"error-datastack" set
|
|
|
|
"error" set
|
|
|
|
] bind ;
|
2005-03-21 14:39:46 -05:00
|
|
|
|
2004-11-26 22:23:57 -05:00
|
|
|
: init-error-handler ( -- )
|
2005-03-21 14:39:46 -05:00
|
|
|
( kernel calls on error )
|
|
|
|
[
|
|
|
|
datastack dupd callstack namestack catchstack
|
|
|
|
save-error rethrow
|
|
|
|
] 5 setenv
|
2004-12-26 01:42:09 -05:00
|
|
|
kernel-error 12 setenv ;
|