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.units
6 continuations definitions destructors effects.parser generic
7 generic.math generic.parser generic.single grouping io
8 io.encodings io.styles kernel kernel.private lexer make math
9 math.order math.parser namespaces parser prettyprint sequences
10 sequences.private slots source-files.errors strings
11 strings.parser summary system vocabs vocabs.loader
13 FROM: namespaces => change-global ;
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 . ;
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 : c-string-error. ( obj -- )
108 "Cannot convert to C string: " write third . ;
110 : ffi-error. ( obj -- )
111 "FFI error" print drop ;
113 : undefined-symbol-error. ( obj -- )
114 "Cannot resolve C library function" print
115 "Symbol: " write dup third symbol>string print
116 "Library: " write fourth .
117 "You are probably missing a library or the library path is wrong." print
118 "See http://concatenative.org/wiki/view/Factor/Requirements" print ;
120 : stack-underflow. ( obj name -- )
121 write " stack underflow" print drop ;
123 : stack-overflow. ( obj name -- )
124 write " stack overflow" print drop ;
126 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
127 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
128 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
129 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
130 : callstack-underflow. ( obj -- ) "Call" stack-underflow. ;
131 : callstack-overflow. ( obj -- ) "Call" stack-overflow. ;
133 : memory-error. ( error -- )
134 "Memory protection fault at address " write third .h ;
136 : primitive-error. ( error -- )
137 "Unimplemented primitive" print drop ;
139 : fp-trap-error. ( error -- )
140 "Floating point trap" print drop ;
142 : interrupt-error. ( error -- )
143 "Interrupt" print drop ;
145 PREDICATE: vm-error < array
146 dup length 2 < [ drop f ] [
148 [ first-unsafe "kernel-error" = ]
149 [ second-unsafe 0 kernel-error-count 1 - between? ]
153 : vm-errors ( error -- n errors )
158 [ type-check-error. ]
159 [ divide-by-zero-error. ]
161 [ array-size-error. ]
162 [ 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. ]
177 M: vm-error summary drop "VM error" ;
179 M: vm-error error. dup vm-errors dispatch ;
181 M: vm-error error-help vm-errors nth first ;
184 drop "No suitable method" ;
187 "Generic word " write
189 " does not define a method for the " write
190 dup object>> class-of pprint
192 "Dispatching on object: " write object>> short. ;
194 M: bad-slot-value summary drop "Bad store to specialized slot" ;
196 M: bad-slot-name summary drop "Bad slot name in object literal" ;
198 M: no-math-method summary
199 drop "No suitable arithmetic method" ;
201 M: no-next-method summary
202 drop "Executing call-next-method from least-specific method" ;
204 M: inconsistent-next-method summary
205 drop "Executing call-next-method with inconsistent parameters" ;
207 M: check-method-error summary
208 drop "Invalid parameters for create-method" ;
210 M: not-a-tuple summary
213 M: bad-superclass summary
214 drop "Tuple classes can only inherit from non-final tuple classes" ;
216 M: bad-initial-value summary
217 drop "Incompatible initial value" ;
220 drop "Fall-through in cond" ;
223 drop "Fall-through in case" ;
225 M: slice-error summary
226 drop "Cannot create slice" ;
228 M: bounds-error summary drop "Sequence index out of bounds" ;
230 M: groups-error summary drop "Non positive group size" ;
232 M: condition error. error>> error. ;
234 M: condition summary error>> summary ;
236 M: condition error-help error>> error-help ;
238 M: assert summary drop "Assertion failed" ;
240 M: assert-sequence summary drop "Assertion failed" ;
242 M: assert-sequence error.
243 standard-table-style [
244 [ "=== Expected:" print expected>> stack. ]
245 [ "=== Got:" print got>> stack. ] bi
248 M: immutable summary drop "Sequence is immutable" ;
250 M: redefine-error error.
251 "Re-definition of " write
254 M: undefined-word summary
255 word>> undefined-word?
256 "Cannot execute a deferred word before it has been defined"
257 "Cannot execute a word before it has been compiled"
260 M: no-compilation-unit error.
261 "Attempting to define " write
263 " outside of a compilation unit" print ;
266 drop "Vocabulary does not exist" ;
268 M: encode-error summary drop "Character encoding error" ;
270 M: decode-error summary drop "Character decoding error" ;
272 M: bad-create summary drop "Bad parameters to create" ;
274 M: cannot-be-inline summary drop "This type of word cannot be inlined" ;
276 M: attempt-all-error summary drop "Nothing to attempt" ;
278 M: already-disposed summary drop "Attempting to operate on disposed object" ;
280 M: no-current-vocab-error summary
281 drop "Not in a vocabulary; IN: form required" ;
283 M: no-word-error summary
286 "” found in current vocabulary search path" surround ;
288 M: no-word-error error. summary print ;
290 M: no-word-in-vocab summary
291 [ vocab>> ] [ word>> ] bi
292 [ "No word named “" % % "” found in “" % % "” vocabulary" % ] "" make ;
294 M: no-word-in-vocab error. summary print ;
296 M: ambiguous-use-error summary
298 "More than one vocabulary defines a word named “" "”" surround ;
300 M: ambiguous-use-error error. summary print ;
302 M: staging-violation summary
304 "A parsing word cannot be used in the same file it is defined in." ;
306 M: bad-number summary
307 drop "Bad number literal" ;
309 M: duplicate-slot-names summary
310 drop "Duplicate slot names" ;
312 M: invalid-slot-name summary
313 drop "Invalid slot name" ;
315 M: bad-inheritance summary
316 drop "Circularity in inheritance chain" ;
318 M: not-in-a-method-error summary
319 drop "call-next-method can only be called in a method definition" ;
321 M: version-control-merge-conflict summary
322 drop "Version control merge conflict in source code" ;
324 GENERIC: expected>string ( obj -- str )
326 M: f expected>string drop "end of input" ;
327 M: word expected>string name>> ;
328 M: string expected>string ;
332 dup want>> expected>string write
334 got>> expected>string print ;
336 M: lexer-error error.
337 [ lexer-dump ] [ error>> error. ] bi ;
339 M: lexer-error summary
342 M: lexer-error compute-restarts
343 error>> compute-restarts ;
345 M: lexer-error error-help
348 M: bad-effect summary
349 drop "Bad stack effect declaration" ;
351 M: invalid-row-variable summary
352 drop "Stack effect row variables can only occur as the first input or output" ;
354 M: row-variable-can't-have-type summary
355 drop "Stack effect row variables cannot have a declared type" ;
358 "Bad escape code: \\" write char>> write nl ;
360 M: bad-literal-tuple summary drop "Bad literal tuple" ;
362 M: check-mixin-class-error summary drop "Not a mixin class" ;
364 M: not-found-in-roots summary
365 path>> "Cannot resolve vocab: " prepend ;
367 M: wrong-values summary drop "Quotation's stack effect does not match call site" ;
369 M: stack-effect-omits-dashes summary drop "Stack effect must contain “--”" ;
371 { "threads" "debugger" } "debugger.threads" require-when