Strange rebol bug: error needs a value
-
13-09-2019 - |
Question
When executing
do-file: func[file][
if error? error: try [
if (find [%.r %.cgi] (suffix? file)) [
do file
]
][
disarm error
print ["error executing " file]
input
]
]
foreach-file: func [
"Perform function on each file in selected directory recursively"
dir [file! url!] "Directory to look in"
act [function!] "Function to perform (filename is unput to function)"
/directory "Perform function also on directories"
/local f files
][
if not equal? last dir #"/" [
dir: to-rebol-file join dir #"/"
]
files: attempt [read dir]
either none? files [return][
foreach file files [
f: join dir file
either dir? f [
either directory [
act f
foreach-file/directory f :act
][
foreach-file f :act
]
][act f]
]
]
]
feach-file %test/ :do-file
where %test would contain a file with just rebo header:
rebol []
The program stops with an error instead of disarming the error !
It doesn't give an error if the file contains something like
rebol []
test: context []
but it would fail again if it contains
rebol []
print ""
Why ?
Solution
A set word must be supplied with a value as illustrated by this console session:
a: func [] [#[unset!]] b: a ** Script Error: b needs a value ** Near: b: a
The solution is to use set/any instead of a set word.
? set USAGE: SET word value /any /pad
DESCRIPTION: Sets a word, block of words, or object to specified value(s). SET is a native value.
ARGUMENTS: word -- Word or words to set (Type: any-word block object) value -- Value or block of values (Type: any-type)
REFINEMENTS: /any -- Allows setting words to any value. /pad -- For objects, if block is too short, remaining words are set to NONE.
You can use something like:
if error? set/any 'error try [] [disarm error] == none
By the way, you can find the answers to many of your questions through the Rebol Mailing List Archive at http://www.rebol.org/ml-index.r.
OTHER TIPS
do-file: func [ file
/local err
][
if error? set/any 'err try [
if find [%.r %.cgi] suffix? file [
do file
]
][
print ["error executing " file]
print mold disarm err
]
]
Those parentheses were unnecessary.
Here's an alternate style
do-file: func [file] [
/local err
] [
if error? set/any 'err try [
all [
find [%.r %.cgi] suffix? file
do file
]
] [
print ["error executing " file]
print mold disarm err
]
]
There is no a valid value returned when success do a file. while set-word need a value, set/any can accept any value.