basis,extra: refactorings to use the ignore-error and ignore-error/f words

char-rename
Björn Lindqvist 2016-11-18 23:39:53 +01:00
parent e4b961a26e
commit 00d4572e6c
7 changed files with 29 additions and 45 deletions

View File

@ -46,4 +46,4 @@ PRIVATE>
{ [ dup ends-with-terminate? ] [ out-d [ f swap <#push> ] map append ] } { [ dup ends-with-terminate? ] [ out-d [ f swap <#push> ] map append ] }
[ in-d' out-d [ [ length ] bi@ assert= ] [ <#copy> suffix ] 2bi ] [ in-d' out-d [ [ length ] bi@ assert= ] [ <#copy> suffix ] 2bi ]
} cond } cond
] [ dup inference-error? [ drop f ] [ rethrow ] if ] recover ; ] [ inference-error? ] ignore-error/f ;

View File

@ -156,9 +156,7 @@ ERROR: uninferable ;
] if ; ] if ;
: infer-value ( value-info -- effect/f ) : infer-value ( value-info -- effect/f )
[ (infer-value) ] '[ _ (infer-value) ] [ uninferable? ] ignore-error/f ;
[ dup uninferable? [ 2drop f ] [ rethrow ] if ]
recover ;
: (value>quot) ( value-info -- quot ) : (value>quot) ( value-info -- quot )
dup literal?>> [ dup literal?>> [

View File

@ -1,8 +1,6 @@
USING: accessors assocs couchdb furnace.auth.providers USING: accessors assocs base64 byte-arrays combinators.short-circuit
json.writer kernel mirrors sequences urls urls.encoding continuations couchdb fry furnace.auth.providers json.writer kernel
arrays furnace.auth byte-arrays combinators.short-circuit locals make mirrors namespaces sequences strings urls urls.encoding ;
strings continuations combinators base64 make
locals namespaces ;
IN: furnace.auth.providers.couchdb IN: furnace.auth.providers.couchdb
! !!! Implement the authentication protocol for CouchDB. ! !!! Implement the authentication protocol for CouchDB.
@ -57,13 +55,10 @@ TUPLE: couchdb-auth-provider
prefix>> [ % url-encode-full % "!" % url-encode-full % ] "" make ; prefix>> [ % url-encode-full % "!" % url-encode-full % ] "" make ;
: (reserve) ( value name -- id/f ) : (reserve) ( value name -- id/f )
reservation-id '[
get-url _ _ reservation-id get-url
[ H{ } clone swap couch-put
H{ } clone >json swap couch-put ] [ is-couchdb-conflict-error? ] ignore-error/f ;
] [
nip dup is-couchdb-conflict-error? [ drop f ] [ rethrow ] if
] recover ;
! Don't reserve false values (e.g. if the email field is f, don't reserve f, ! Don't reserve false values (e.g. if the email field is f, don't reserve f,
! or the first user who registers without an email address will block all ! or the first user who registers without an email address will block all
@ -78,13 +73,11 @@ TUPLE: couchdb-auth-provider
couch-delete drop ; couch-delete drop ;
: unreserve-from-id ( id -- ) : unreserve-from-id ( id -- )
[ '[
get-url dup couch-get _ get-url dup couch-get
"_rev" of "rev" set-query-param "_rev" of "rev" set-query-param
couch-delete drop couch-delete drop
] [ ] [ is-couchdb-not-found-error? ] ignore-error ;
dup is-couchdb-not-found-error? [ 2drop ] [ rethrow ] if
] recover ;
:: (reserve-multiple) ( hash keys made -- ? ) :: (reserve-multiple) ( hash keys made -- ? )
keys empty? [ t ] [ keys empty? [ t ] [

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: byte-arrays math io.backend io.files.info USING: byte-arrays fry math io.backend io.files.info
io.files.windows kernel windows.kernel32 io.files.windows kernel windows.kernel32
windows.time windows.types windows accessors alien.c-types windows.time windows.types windows accessors alien.c-types
combinators generalizations system alien.strings combinators generalizations system alien.strings
@ -213,12 +213,10 @@ CONSTANT: names-buf-length 16384
] with-destructors ; ] with-destructors ;
! Suppress T{ windows-error f 2 "The system cannot find the file specified." } ! Suppress T{ windows-error f 2 "The system cannot find the file specified." }
: volume>paths ( string -- array ) : volume>paths ( string -- array/f )
[ (volume>paths) ] curry '[ _ (volume>paths) ] [
[ { [ windows-error? ] [ n>> ERROR_FILE_NOT_FOUND = ] } 1&&
dup { [ windows-error? ] [ n>> ERROR_FILE_NOT_FOUND = ] } 1&& ] ignore-error/f ;
[ drop { } ] [ rethrow ] if
] recover ;
! Can error with T{ windows-error f 21 "The device is not ready." } ! Can error with T{ windows-error f 21 "The device is not ready." }
! if there is a D: that is not ready, for instance. Ignore these drives. ! if there is a D: that is not ready, for instance. Ignore these drives.

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Doug Coleman, Slava Pestov. ! Copyright (C) 2008 Doug Coleman, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.data arrays classes.struct USING: accessors alien alien.data arrays classes.struct
combinators continuations destructors io.backend combinators continuations destructors fry io.backend
io.encodings.string io.encodings.utf16n io.files.windows io.encodings.string io.encodings.utf16n io.files.windows
io.monitors io.pathnames io.ports kernel literals locals make io.monitors io.pathnames io.ports kernel literals locals make
math sequences system threads windows.errors windows.kernel32 math sequences system threads windows.errors windows.kernel32
@ -85,8 +85,8 @@ TUPLE: win32-monitor < monitor port ;
dup fill-queue (fill-queue-thread) ; dup fill-queue (fill-queue-thread) ;
: fill-queue-thread ( monitor -- ) : fill-queue-thread ( monitor -- )
[ dup fill-queue (fill-queue-thread) ] '[ _ dup fill-queue (fill-queue-thread) ]
[ dup already-disposed? [ 2drop ] [ rethrow ] if ] recover ; [ already-disposed? ] ignore-error ;
M:: windows (monitor) ( path recursive? mailbox -- monitor ) M:: windows (monitor) ( path recursive? mailbox -- monitor )
[ [

View File

@ -1,10 +1,9 @@
! Copyright (C) 2003, 2009 Slava Pestov. ! Copyright (C) 2003, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors colors colors.constants USING: accessors colors colors.constants combinators.short-circuit
combinators.short-circuit compiler.units continuations debugger compiler.units continuations debugger fry io io.styles kernel lexer
fry io io.styles kernel lexer literals locals math math.parser locals math math.parser namespaces parser parser.notes prettyprint
namespaces parser parser.notes prettyprint sequences sets sequences sets source-files.errors system vocabs vocabs.loader
source-files.errors system vocabs vocabs.loader
vocabs.parser ; vocabs.parser ;
IN: listener IN: listener
@ -40,10 +39,8 @@ SYMBOL: handle-ctrl-break
[ [ parse-lines ] with-ctrl-break ] with-compilation-unit ; [ [ parse-lines ] with-ctrl-break ] with-compilation-unit ;
: read-quot-step ( lines -- quot/f ) : read-quot-step ( lines -- quot/f )
[ parse-lines-interactive ] [ '[ _ parse-lines-interactive ]
dup error>> unexpected-eof? [ error>> unexpected-eof? ] ignore-error/f ;
[ 2drop f ] [ rethrow ] if
] recover ;
: read-quot-loop ( stream accum -- quot/f ) : read-quot-loop ( stream accum -- quot/f )
over stream-readln dup [ over stream-readln dup [

View File

@ -1,9 +1,9 @@
! Copyright (C) 2008, 2009 Alex Chapman ! Copyright (C) 2008, 2009 Alex Chapman
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs continuations debugger hashtables http USING: accessors assocs continuations debugger fry hashtables http
http.client io io.encodings.string io.encodings.utf8 json.reader http.client io io.encodings.string io.encodings.utf8 json.reader
json.writer kernel locals make math math.parser namespaces sequences json.writer kernel locals make math math.parser namespaces sequences
strings urls urls.encoding vectors ; strings urls.encoding vectors ;
IN: couchdb IN: couchdb
! NOTE: This code only works with the latest couchdb (0.9.*), because old ! NOTE: This code only works with the latest couchdb (0.9.*), because old
@ -111,9 +111,7 @@ C: <db> db
f swap db-url couch-put response-ok* ; f swap db-url couch-put response-ok* ;
: ensure-db ( db -- ) : ensure-db ( db -- )
[ create-db ] [ '[ _ create-db ] [ file-exists-error? ] ignore-error ;
dup file-exists-error? [ 2drop ] [ rethrow ] if
] recover ;
: delete-db ( db -- ) : delete-db ( db -- )
db-url couch-delete drop ; db-url couch-delete drop ;