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 : c-string-error. ( obj -- )
105 "Cannot convert to C string: " write third . ;
107 : ffi-error. ( obj -- )
108 "FFI error" print drop ;
110 : undefined-symbol-error. ( obj -- )
111 "Cannot resolve C library function" print
112 "Symbol: " write dup third symbol>string print
113 "Library: " write fourth .
114 "You are probably missing a library or the library path is wrong." print
115 "See http://concatenative.org/wiki/view/Factor/Requirements" print ;
117 : stack-underflow. ( obj name -- )
118 write " stack underflow" print drop ;
120 : stack-overflow. ( obj name -- )
121 write " stack overflow" print drop ;
123 : datastack-underflow. ( obj -- ) "Data" stack-underflow. ;
124 : datastack-overflow. ( obj -- ) "Data" stack-overflow. ;
125 : retainstack-underflow. ( obj -- ) "Retain" stack-underflow. ;
126 : retainstack-overflow. ( obj -- ) "Retain" stack-overflow. ;
127 : callstack-underflow. ( obj -- ) "Call" stack-underflow. ;
128 : callstack-overflow. ( obj -- ) "Call" stack-overflow. ;
130 : memory-error. ( error -- )
131 "Memory protection fault at address " write third .h ;
133 : primitive-error. ( error -- )
134 "Unimplemented primitive" print drop ;
136 : fp-trap-error. ( error -- )
137 "Floating point trap" print drop ;
139 : interrupt-error. ( error -- )
140 "Interrupt" print drop ;
142 PREDICATE: vm-error < array
143 dup length 2 < [ drop f ] [
145 [ first-unsafe "kernel-error" = ]
146 [ second-unsafe 0 kernel-error-count 1 - between? ]
150 : vm-errors ( error -- n errors )
155 [ type-check-error. ]
156 [ divide-by-zero-error. ]
158 [ array-size-error. ]
161 [ undefined-symbol-error. ]
162 [ datastack-underflow. ]
163 [ datastack-overflow. ]
164 [ retainstack-underflow. ]
165 [ retainstack-overflow. ]
166 [ callstack-underflow. ]
167 [ callstack-overflow. ]
173 M: vm-error summary drop "VM error" ;
175 M: vm-error error. dup vm-errors dispatch ;
177 M: vm-error error-help vm-errors nth first ;
180 drop "No suitable method" ;
183 "Generic word " write
185 " does not define a method for the " write
186 dup object>> class-of pprint
188 "Dispatching on object: " write object>> short. ;
190 M: bad-slot-value summary drop "Bad store to specialized slot" ;
192 M: bad-slot-name summary drop "Bad slot name in object literal" ;
194 M: no-math-method summary
195 drop "No suitable arithmetic method" ;
197 M: no-next-method summary
198 drop "Executing call-next-method from least-specific method" ;
200 M: inconsistent-next-method summary
201 drop "Executing call-next-method with inconsistent parameters" ;
203 M: check-method-error summary
204 drop "Invalid parameters for create-method" ;
206 M: not-a-tuple summary
209 M: bad-superclass summary
210 drop "Tuple classes can only inherit from non-final tuple classes" ;
212 M: bad-initial-value summary
213 drop "Incompatible initial value" ;
216 drop "Fall-through in cond" ;
219 drop "Fall-through in case" ;
221 M: slice-error summary
222 drop "Cannot create slice" ;
224 M: bounds-error summary drop "Sequence index out of bounds" ;
226 M: groups-error summary drop "Non positive group size" ;
228 M: condition error. error>> error. ;
230 M: condition summary error>> summary ;
232 M: condition error-help error>> error-help ;
234 M: assert summary drop "Assertion failed" ;
236 M: assert-sequence summary drop "Assertion failed" ;
238 M: assert-sequence error.
239 standard-table-style [
240 [ "=== Expected:" print expected>> stack. ]
241 [ "=== Got:" print got>> stack. ] bi
244 M: immutable summary drop "Sequence is immutable" ;
246 M: redefine-error error.
247 "Re-definition of " write
250 M: undefined-word summary
251 word>> undefined-word?
252 "Cannot execute a deferred word before it has been defined"
253 "Cannot execute a word before it has been compiled"
256 M: no-compilation-unit error.
257 "Attempting to define " write
259 " outside of a compilation unit" print ;
262 drop "Vocabulary does not exist" ;
264 M: encode-error summary drop "Character encoding error" ;
266 M: decode-error summary drop "Character decoding error" ;
268 M: bad-create summary drop "Bad parameters to create" ;
270 M: cannot-be-inline summary drop "This type of word cannot be inlined" ;
272 M: attempt-all-error summary drop "Nothing to attempt" ;
274 M: already-disposed summary drop "Attempting to operate on disposed object" ;
276 M: no-current-vocab-error summary
277 drop "Not in a vocabulary; IN: form required" ;
279 M: no-word-error summary
282 "” found in current vocabulary search path" surround ;
284 M: no-word-error error. summary print ;
286 M: no-word-in-vocab summary
287 [ vocab>> ] [ word>> ] bi
288 [ "No word named “" % % "” found in “" % % "” vocabulary" % ] "" make ;
290 M: no-word-in-vocab error. summary print ;
292 M: ambiguous-use-error summary
294 "More than one vocabulary defines a word named “" "”" surround ;
296 M: ambiguous-use-error error. summary print ;
298 M: staging-violation summary
300 "A parsing word cannot be used in the same file it is defined in." ;
302 M: bad-number summary
303 drop "Bad number literal" ;
305 M: duplicate-slot-names summary
306 drop "Duplicate slot names" ;
308 M: invalid-slot-name summary
309 drop "Invalid slot name" ;
311 M: bad-inheritance summary
312 drop "Circularity in inheritance chain" ;
314 M: not-in-a-method-error summary
315 drop "call-next-method can only be called in a method definition" ;
317 M: version-control-merge-conflict summary
318 drop "Version control merge conflict in source code" ;
320 GENERIC: expected>string ( obj -- str )
322 M: f expected>string drop "end of input" ;
323 M: word expected>string name>> ;
324 M: string expected>string ;
328 dup want>> expected>string write
330 got>> expected>string print ;
332 M: lexer-error error.
333 [ lexer-dump ] [ error>> error. ] bi ;
335 M: lexer-error summary
338 M: lexer-error compute-restarts
339 error>> compute-restarts ;
341 M: lexer-error error-help
344 M: bad-effect summary
345 drop "Bad stack effect declaration" ;
347 M: invalid-row-variable summary
348 drop "Stack effect row variables can only occur as the first input or output" ;
350 M: row-variable-can't-have-type summary
351 drop "Stack effect row variables cannot have a declared type" ;
354 "Bad escape code: \\" write char>> write nl ;
356 M: bad-literal-tuple summary drop "Bad literal tuple" ;
358 M: check-mixin-class-error summary drop "Not a mixin class" ;
360 M: not-found-in-roots summary
361 path>> "Cannot resolve vocab: " prepend ;
363 M: wrong-values summary drop "Quotation's stack effect does not match call site" ;
365 M: stack-effect-omits-dashes summary drop "Stack effect must contain “--”" ;
367 { "threads" "debugger" } "debugger.threads" require-when