1 ! Copyright (C) 2004, 2011 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.strings arrays assocs classes
4 classes.builtin classes.mixin classes.tuple classes.tuple.parser
5 combinators combinators.short-circuit compiler.errors
6 compiler.units continuations definitions destructors
7 effects.parser fry generic generic.math generic.parser
8 generic.single grouping io io.encodings io.styles kernel
9 kernel.private lexer libc make math math.order math.parser
10 math.ratios namespaces parser prettyprint sequences
11 sequences.private slots source-files.errors strings
12 strings.parser summary system vocabs vocabs.loader vocabs.parser
16 GENERIC: error-help ( error -- topic )
18 M: object error-help drop f ;
20 M: tuple error-help class-of ;
22 M: source-file-error error-help error>> error-help ;
24 GENERIC: error. ( error -- )
26 M: object error. short. ;
28 M: string error. print ;
30 : traceback-link. ( continuation -- )
31 "[" write [ "Traceback" ] dip write-object "]" print ;
34 error-continuation get data>> stack. ;
37 error-continuation get retain>> stack. ;
40 error-continuation get call>> callstack. ;
42 : :get ( variable -- value )
43 error-continuation get name>> assoc-stack ;
46 1 - restarts [ nth f ] change-global continue-restart ;
48 : :1 ( -- * ) 1 :res ;
49 : :2 ( -- * ) 2 :res ;
50 : :3 ( -- * ) 3 :res ;
52 : restart. ( restart n -- )
54 1 + dup 3 <= [ ":" % # " " % ] [ # " :res " % ] if
61 "The following restarts are available:" print
63 [ restart. ] each-index
66 : print-error ( error -- )
67 [ error. flush ] curry
68 [ [ "Error in print-error!" print drop ] with-global ]
72 error get print-error ;
74 : print-error-and-restarts ( error -- )
78 "Type :help for debugging help." print flush ;
81 [ print-error-and-restarts ] recover ; inline
83 : expired-error. ( obj -- )
84 "Object did not survive image save/load: " write third . ;
86 : io-error. ( error -- )
87 "I/O error #" write third [ . ] [ strerror print ] bi ;
89 : type-check-error. ( obj -- )
90 "Type check error" print
91 "Object: " write dup fourth short.
92 "Object type: " write dup fourth class-of .
93 "Expected type: " write third type>class . ;
95 : divide-by-zero-error. ( obj -- )
96 "Division by zero" print drop ;
98 HOOK: signal-error. os ( obj -- )
100 : array-size-error. ( obj -- )
101 "Invalid array size: " write dup third .
102 "Maximum: " write fourth 1 - . ;
104 : fixnum-range-error. ( obj -- )
105 "Cannot convert to fixnum: " write third . ;
107 : ffi-error. ( obj -- )
108 "FFI error" print drop ;
110 : find-ffi-error ( string -- error )
111 [ linkage-errors get ] dip
112 '[ nip asset>> name>> _ = ] assoc-find drop nip
113 [ error>> message>> ] [ "none" ] if* ;
115 : undefined-symbol-error. ( obj -- )
116 "Cannot resolve C library function" print
117 "Library: " write dup fourth .
119 [ "Symbol: " write print ]
120 [ "DlError: " write find-ffi-error print ] bi
121 "See http://concatenative.org/wiki/view/Factor/Requirements" print ;
123 : stack-underflow. ( obj name -- )
124 write " stack underflow" print drop ;
126 : stack-overflow. ( obj name -- )
127 write " stack overflow" print drop ;
129 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
130 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
131 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
132 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
133 : callstack-underflow. ( obj -- ) "Call" stack-underflow. ;
134 : callstack-overflow. ( obj -- ) "Call" stack-overflow. ;
136 : memory-error. ( error -- )
137 "Memory protection fault at address " write third .h ;
139 : primitive-error. ( error -- )
140 "Unimplemented primitive" print drop ;
142 : fp-trap-error. ( error -- )
143 "Floating point trap" print drop ;
145 : interrupt-error. ( error -- )
146 "Interrupt" print drop ;
148 : callback-space-overflow. ( error -- )
149 "Callback space overflow" print drop ;
151 PREDICATE: vm-error < array
152 dup length 2 < [ drop f ] [
154 [ first-unsafe "kernel-error" = ]
155 [ second-unsafe 0 kernel-error-count 1 - between? ]
159 : vm-errors ( error -- n errors )
164 [ type-check-error. ]
165 [ divide-by-zero-error. ]
167 [ array-size-error. ]
168 [ fixnum-range-error. ]
170 [ undefined-symbol-error. ]
171 [ datastack-underflow. ]
172 [ datastack-overflow. ]
173 [ retainstack-underflow. ]
174 [ retainstack-overflow. ]
175 [ callstack-underflow. ]
176 [ callstack-overflow. ]
180 [ callback-space-overflow. ]
183 M: vm-error summary drop "VM error" ;
185 M: vm-error error. dup vm-errors dispatch ;
187 M: vm-error error-help vm-errors nth first ;
189 M: division-by-zero summary
190 drop "Division by zero" ;
193 drop "No suitable method" ;
196 "Generic word " write
198 " does not define a method for the " write
199 dup object>> class-of pprint
201 "Dispatching on object: " write object>> short. ;
203 M: bad-slot-value summary drop "Bad store to specialized slot" ;
205 M: bad-slot-name summary drop "Bad slot name in object literal" ;
207 M: bad-vocab-name summary drop "Vocab name cannot contain \":/\\ \"" ;
209 M: no-math-method summary
210 drop "No suitable arithmetic method" ;
212 M: no-next-method summary
213 drop "Executing call-next-method from least-specific method" ;
215 M: inconsistent-next-method summary
216 drop "Executing call-next-method with inconsistent parameters" ;
218 M: check-method-error summary
219 drop "Invalid parameters for create-method" ;
221 M: not-a-tuple summary
224 M: bad-superclass summary
225 drop "Tuple classes can only inherit from non-final tuple classes" ;
227 M: bad-initial-value summary
228 drop "Incompatible initial value" ;
231 drop "Fall-through in cond" ;
234 drop "Fall-through in case" ;
236 M: slice-error summary
237 "Cannot create slice" swap {
238 { [ dup from>> 0 < ] [ ": from < 0" ] }
239 { [ dup [ to>> ] [ seq>> length ] bi > ] [ ": to > length" ] }
240 { [ dup [ from>> ] [ to>> ] bi > ] [ ": from > to" ] }
244 M: bounds-error summary drop "Sequence index out of bounds" ;
246 M: groups-error summary drop "Non positive group size" ;
248 M: condition error. error>> error. ;
250 M: condition summary error>> summary ;
252 M: condition error-help error>> error-help ;
254 M: assert summary drop "Assertion failed" ;
256 M: assert-sequence summary drop "Assertion failed" ;
258 M: assert-sequence error.
259 standard-table-style [
260 [ "=== Expected:" print expected>> stack. ]
261 [ "=== Got:" print got>> stack. ] bi
264 M: immutable summary drop "Sequence is immutable" ;
266 M: redefine-error error.
267 "Re-definition of " write
270 M: undefined-word summary
271 word>> undefined-word?
272 "Cannot execute a deferred word before it has been defined"
273 "Cannot execute a word before it has been compiled"
276 M: no-compilation-unit error.
277 "Attempting to define " write
279 " outside of a compilation unit" print ;
282 drop "Vocabulary does not exist" ;
284 M: encode-error summary drop "Character encoding error" ;
286 M: decode-error summary drop "Character decoding error" ;
288 M: bad-create summary drop "Bad parameters to create" ;
290 M: cannot-be-inline summary drop "This type of word cannot be inlined" ;
292 M: attempt-all-error summary drop "Nothing to attempt" ;
294 M: already-disposed summary drop "Attempting to operate on disposed object" ;
296 M: no-current-vocab-error summary
297 drop "Not in a vocabulary; IN: form required" ;
299 M: no-word-error summary
302 "” found in current vocabulary search path" surround ;
304 M: no-word-error error. summary print ;
306 M: no-word-in-vocab summary
307 [ vocab>> ] [ word>> ] bi
308 [ "No word named “" % % "” found in “" % % "” vocabulary" % ] "" make ;
310 M: no-word-in-vocab error. summary print ;
312 M: ambiguous-use-error summary
314 "More than one vocabulary defines a word named “" "”" surround ;
316 M: ambiguous-use-error error. summary print ;
318 M: staging-violation summary
320 "A parsing word cannot be used in the same file it is defined in." ;
322 M: bad-number summary
323 drop "Bad number literal" ;
325 M: duplicate-slot-names summary
326 drop "Duplicate slot names" ;
328 M: invalid-slot-name summary
329 drop "Invalid slot name" ;
331 M: bad-inheritance summary
332 drop "Circularity in inheritance chain" ;
334 M: not-in-a-method-error summary
335 drop "call-next-method can only be called in a method definition" ;
337 M: version-control-merge-conflict summary
338 drop "Version control merge conflict in source code" ;
340 GENERIC: expected>string ( obj -- str )
342 M: f expected>string drop "end of input" ;
343 M: word expected>string name>> ;
344 M: string expected>string ;
348 dup want>> expected>string write
350 got>> expected>string print ;
352 M: lexer-error error.
353 [ lexer-dump ] [ error>> error. ] bi ;
355 M: lexer-error summary
358 M: lexer-error compute-restarts
359 error>> compute-restarts ;
361 M: lexer-error error-help
364 M: bad-effect summary
365 drop "Bad stack effect declaration" ;
367 M: invalid-row-variable summary
368 drop "Stack effect row variables can only occur as the first input or output" ;
370 M: row-variable-can't-have-type summary
371 drop "Stack effect row variables cannot have a declared type" ;
374 "Bad escape code: \\" write char>> write nl ;
376 M: bad-literal-tuple summary drop "Bad literal tuple" ;
378 M: check-mixin-class-error summary drop "Not a mixin class" ;
380 M: not-found-in-roots summary
381 path>> "Cannot resolve vocab: " prepend ;
383 M: wrong-values summary drop "Quotation's stack effect does not match call site" ;
385 M: stack-effect-omits-dashes summary drop "Stack effect must contain “--”" ;
387 { "threads" "debugger" } "debugger.threads" require-when