1 ! Copyright (C) 2004, 2011 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.strings arrays assocs classes
4 classes.builtin classes.mixin classes.tuple classes.tuple.parser
5 combinators combinators.short-circuit compiler.errors compiler.units
6 continuations definitions destructors effects.parser fry generic
7 generic.math generic.parser generic.single grouping io io.encodings
8 io.styles kernel kernel.private lexer libc make math math.order
9 math.parser math.ratios namespaces parser prettyprint sequences
10 sequences.private slots source-files.errors strings strings.parser
11 summary system vocabs vocabs.loader vocabs.parser words ;
14 GENERIC: error-help ( error -- topic )
16 M: object error-help drop f ;
18 M: tuple error-help class-of ;
20 M: source-file-error error-help error>> error-help ;
22 GENERIC: error. ( error -- )
24 M: object error. short. ;
26 M: string error. print ;
28 : traceback-link. ( continuation -- )
29 "[" write [ "Traceback" ] dip write-object "]" print ;
32 error-continuation get data>> stack. ;
35 error-continuation get retain>> stack. ;
38 error-continuation get call>> callstack. ;
40 : :get ( variable -- value )
41 error-continuation get name>> assoc-stack ;
44 1 - restarts [ nth f ] change-global continue-restart ;
46 : :1 ( -- * ) 1 :res ;
47 : :2 ( -- * ) 2 :res ;
48 : :3 ( -- * ) 3 :res ;
50 : restart. ( restart n -- )
52 1 + dup 3 <= [ ":" % # " " % ] [ # " :res " % ] if
59 "The following restarts are available:" print
61 [ restart. ] each-index
64 : print-error ( error -- )
65 [ error. flush ] curry
66 [ [ "Error in print-error!" print drop ] with-global ]
70 error get print-error ;
72 : print-error-and-restarts ( error -- )
76 "Type :help for debugging help." print flush ;
79 [ print-error-and-restarts ] recover ; inline
81 : expired-error. ( obj -- )
82 "Object did not survive image save/load: " write third . ;
84 : io-error. ( error -- )
85 "I/O error #" write third [ . ] [ strerror print ] bi ;
87 : type-check-error. ( obj -- )
88 "Type check error" print
89 "Object: " write dup fourth short.
90 "Object type: " write dup fourth class-of .
91 "Expected type: " write third type>class . ;
93 : divide-by-zero-error. ( obj -- )
94 "Division by zero" print drop ;
96 HOOK: signal-error. os ( obj -- )
98 : array-size-error. ( obj -- )
99 "Invalid array size: " write dup third .
100 "Maximum: " write fourth 1 - . ;
102 : fixnum-range-error. ( obj -- )
103 "Cannot convert to fixnum: " write third . ;
105 : ffi-error. ( obj -- )
106 "FFI error" print drop ;
108 : find-ffi-error ( string -- error )
109 [ linkage-errors get ] dip
110 '[ nip asset>> name>> _ = ] assoc-find drop nip
111 [ error>> message>> ] [ "none" ] if* ;
113 : undefined-symbol-error. ( obj -- )
114 "Cannot resolve C library function" print
115 "Library: " write dup fourth .
117 [ "Symbol: " write print ]
118 [ "DlError: " write find-ffi-error print ] bi
119 "See http://concatenative.org/wiki/view/Factor/Requirements" print ;
121 : stack-underflow. ( obj name -- )
122 write " stack underflow" print drop ;
124 : stack-overflow. ( obj name -- )
125 write " stack overflow" print drop ;
127 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
128 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
129 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
130 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
131 : callstack-underflow. ( obj -- ) "Call" stack-underflow. ;
132 : callstack-overflow. ( obj -- ) "Call" stack-overflow. ;
134 : memory-error. ( error -- )
135 "Memory protection fault at address " write third .h ;
137 : fp-trap-error. ( error -- )
138 "Floating point trap" print drop ;
140 : interrupt-error. ( error -- )
141 "Interrupt" print drop ;
143 : callback-space-overflow. ( error -- )
144 "Callback space overflow" print drop ;
146 PREDICATE: vm-error < array
147 dup length 2 < [ drop f ] [
149 [ first-unsafe KERNEL-ERROR = ]
150 [ second-unsafe 0 kernel-error-count 1 - between? ]
154 : vm-errors ( error -- n errors )
159 [ type-check-error. ]
160 [ divide-by-zero-error. ]
162 [ array-size-error. ]
163 [ fixnum-range-error. ]
165 [ undefined-symbol-error. ]
166 [ datastack-underflow. ]
167 [ datastack-overflow. ]
168 [ retainstack-underflow. ]
169 [ retainstack-overflow. ]
170 [ callstack-underflow. ]
171 [ callstack-overflow. ]
175 [ callback-space-overflow. ]
178 M: vm-error summary drop "VM error" ;
180 M: vm-error error. dup vm-errors dispatch ;
182 M: vm-error error-help vm-errors nth first ;
184 M: division-by-zero summary
185 drop "Division by zero" ;
188 drop "No suitable method" ;
191 "Generic word " write
193 " does not define a method for the " write
194 dup object>> class-of pprint
196 "Dispatching on object: " write object>> short. ;
198 M: bad-slot-value summary drop "Bad store to specialized slot" ;
200 M: bad-slot-name summary drop "Bad slot name in object literal" ;
202 M: bad-vocab-name summary drop "Vocab name cannot contain \":/\\ \"" ;
204 M: no-math-method summary
205 drop "No suitable arithmetic method" ;
207 M: no-next-method summary
208 drop "Executing call-next-method from least-specific method" ;
210 M: inconsistent-next-method summary
211 drop "Executing call-next-method with inconsistent parameters" ;
213 M: check-method-error summary
214 drop "Invalid parameters for create-method" ;
216 M: not-a-tuple summary
219 M: bad-superclass summary
220 drop "Tuple classes can only inherit from non-final tuple classes" ;
222 M: bad-initial-value summary
223 drop "Incompatible initial value" ;
226 drop "Fall-through in cond" ;
229 drop "Fall-through in case" ;
231 M: slice-error summary
232 "Cannot create slice" swap {
233 { [ dup from>> 0 < ] [ ": from < 0" ] }
234 { [ dup [ to>> ] [ seq>> length ] bi > ] [ ": to > length" ] }
235 { [ dup [ from>> ] [ to>> ] bi > ] [ ": from > to" ] }
239 M: bounds-error summary drop "Sequence index out of bounds" ;
241 M: groups-error summary drop "Non positive group size" ;
243 M: condition error. error>> error. ;
245 M: condition summary error>> summary ;
247 M: condition error-help error>> error-help ;
249 M: assert summary drop "Assertion failed" ;
251 M: assert-sequence summary drop "Assertion failed" ;
253 M: assert-sequence error.
254 standard-table-style [
255 [ "=== Expected:" print expected>> stack. ]
256 [ "=== Got:" print got>> stack. ] bi
259 M: immutable summary drop "Sequence is immutable" ;
261 M: redefine-error error.
262 "Re-definition of " write
265 M: undefined-word summary
266 word>> undefined-word?
267 "Cannot execute a deferred word before it has been defined"
268 "Cannot execute a word before it has been compiled"
271 M: no-compilation-unit error.
272 "Attempting to define " write
274 " outside of a compilation unit" print ;
277 drop "Vocabulary does not exist" ;
279 M: encode-error summary drop "Character encoding error" ;
281 M: decode-error summary drop "Character decoding error" ;
283 M: bad-create summary drop "Bad parameters to create" ;
285 M: cannot-be-inline summary drop "This type of word cannot be inlined" ;
287 M: attempt-all-error summary drop "Nothing to attempt" ;
289 M: already-disposed summary drop "Attempting to operate on disposed object" ;
291 M: no-current-vocab-error summary
292 drop "Not in a vocabulary; IN: form required" ;
294 M: no-word-error summary
297 "” found in current vocabulary search path" surround ;
299 M: no-word-error error. summary print ;
301 M: no-word-in-vocab summary
302 [ vocab>> ] [ word>> ] bi
303 [ "No word named “" % % "” found in “" % % "” vocabulary" % ] "" make ;
305 M: no-word-in-vocab error. summary print ;
307 M: ambiguous-use-error summary
309 "The name “" "” resolves to more than one word." surround ;
311 M: ambiguous-use-error error. summary print ;
313 M: staging-violation summary
315 "A parsing word cannot be used in the same file it is defined in." ;
317 M: bad-number summary
318 drop "Bad number literal" ;
320 M: duplicate-slot-names summary
321 drop "Duplicate slot names" ;
323 M: invalid-slot-name summary
324 drop "Invalid slot name" ;
326 M: bad-inheritance summary
327 drop "Circularity in inheritance chain" ;
329 M: not-in-a-method-error summary
330 drop "call-next-method can only be called in a method definition" ;
332 M: version-control-merge-conflict summary
333 drop "Version control merge conflict in source code" ;
335 GENERIC: expected>string ( obj -- str )
337 M: f expected>string drop "end of input" ;
338 M: word expected>string name>> ;
339 M: string expected>string ;
343 dup want>> expected>string write
345 got>> expected>string print ;
347 M: lexer-error error.
348 [ lexer-dump ] [ error>> error. ] bi ;
350 M: lexer-error summary
353 M: lexer-error compute-restarts
354 error>> compute-restarts ;
356 M: lexer-error error-help
359 M: bad-effect summary
360 drop "Bad stack effect declaration" ;
362 M: invalid-row-variable summary
363 drop "Stack effect row variables can only occur as the first input or output" ;
365 M: row-variable-can't-have-type summary
366 drop "Stack effect row variables cannot have a declared type" ;
369 "Bad escape code: \\" write char>> write nl ;
371 M: bad-literal-tuple summary drop "Bad literal tuple" ;
373 M: not-a-mixin-class summary drop "Not a mixin class" ;
375 M: not-found-in-roots summary
376 path>> "Cannot resolve vocab: " prepend ;
378 M: wrong-values summary drop "Quotation's stack effect does not match call site" ;
380 M: stack-effect-omits-dashes summary drop "Stack effect must contain “--”" ;
382 M: callsite-not-compiled summary
383 drop "Caller not compiled with the optimizing compiler" ;
385 { "threads" "debugger" } "debugger.threads" require-when