From 00d4572e6c5c6658cd78137e8e8eecd09aed9784 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B6rn=20Lindqvist?= Date: Fri, 18 Nov 2016 23:39:53 +0100 Subject: [PATCH] basis,extra: refactorings to use the ignore-error and ignore-error/f words --- basis/compiler/tree/builder/builder.factor | 2 +- .../call-effect/call-effect.factor | 4 +-- .../auth/providers/couchdb/couchdb.factor | 27 +++++++------------ basis/io/files/info/windows/windows.factor | 12 ++++----- basis/io/monitors/windows/windows.factor | 6 ++--- basis/listener/listener.factor | 15 +++++------ extra/couchdb/couchdb.factor | 8 +++--- 7 files changed, 29 insertions(+), 45 deletions(-) diff --git a/basis/compiler/tree/builder/builder.factor b/basis/compiler/tree/builder/builder.factor index 3670168c3e..624a54a95b 100644 --- a/basis/compiler/tree/builder/builder.factor +++ b/basis/compiler/tree/builder/builder.factor @@ -46,4 +46,4 @@ PRIVATE> { [ dup ends-with-terminate? ] [ out-d [ f swap <#push> ] map append ] } [ in-d' out-d [ [ length ] bi@ assert= ] [ <#copy> suffix ] 2bi ] } cond - ] [ dup inference-error? [ drop f ] [ rethrow ] if ] recover ; + ] [ inference-error? ] ignore-error/f ; diff --git a/basis/compiler/tree/propagation/call-effect/call-effect.factor b/basis/compiler/tree/propagation/call-effect/call-effect.factor index edb5ce76ba..9b49930d43 100644 --- a/basis/compiler/tree/propagation/call-effect/call-effect.factor +++ b/basis/compiler/tree/propagation/call-effect/call-effect.factor @@ -156,9 +156,7 @@ ERROR: uninferable ; ] if ; : infer-value ( value-info -- effect/f ) - [ (infer-value) ] - [ dup uninferable? [ 2drop f ] [ rethrow ] if ] - recover ; + '[ _ (infer-value) ] [ uninferable? ] ignore-error/f ; : (value>quot) ( value-info -- quot ) dup literal?>> [ diff --git a/basis/furnace/auth/providers/couchdb/couchdb.factor b/basis/furnace/auth/providers/couchdb/couchdb.factor index 62accc6410..a01c80baac 100644 --- a/basis/furnace/auth/providers/couchdb/couchdb.factor +++ b/basis/furnace/auth/providers/couchdb/couchdb.factor @@ -1,8 +1,6 @@ -USING: accessors assocs couchdb furnace.auth.providers -json.writer kernel mirrors sequences urls urls.encoding -arrays furnace.auth byte-arrays combinators.short-circuit -strings continuations combinators base64 make -locals namespaces ; +USING: accessors assocs base64 byte-arrays combinators.short-circuit +continuations couchdb fry furnace.auth.providers json.writer kernel +locals make mirrors namespaces sequences strings urls urls.encoding ; IN: furnace.auth.providers.couchdb ! !!! Implement the authentication protocol for CouchDB. @@ -57,13 +55,10 @@ TUPLE: couchdb-auth-provider prefix>> [ % url-encode-full % "!" % url-encode-full % ] "" make ; : (reserve) ( value name -- id/f ) - reservation-id - get-url - [ - H{ } clone >json swap couch-put - ] [ - nip dup is-couchdb-conflict-error? [ drop f ] [ rethrow ] if - ] recover ; + '[ + _ _ reservation-id get-url + H{ } clone swap couch-put + ] [ is-couchdb-conflict-error? ] ignore-error/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 @@ -78,13 +73,11 @@ TUPLE: couchdb-auth-provider couch-delete drop ; : unreserve-from-id ( id -- ) - [ - get-url dup couch-get + '[ + _ get-url dup couch-get "_rev" of "rev" set-query-param couch-delete drop - ] [ - dup is-couchdb-not-found-error? [ 2drop ] [ rethrow ] if - ] recover ; + ] [ is-couchdb-not-found-error? ] ignore-error ; :: (reserve-multiple) ( hash keys made -- ? ) keys empty? [ t ] [ diff --git a/basis/io/files/info/windows/windows.factor b/basis/io/files/info/windows/windows.factor index 9629253622..8949be4481 100755 --- a/basis/io/files/info/windows/windows.factor +++ b/basis/io/files/info/windows/windows.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Doug Coleman. ! 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 windows.time windows.types windows accessors alien.c-types combinators generalizations system alien.strings @@ -213,12 +213,10 @@ CONSTANT: names-buf-length 16384 ] with-destructors ; ! Suppress T{ windows-error f 2 "The system cannot find the file specified." } -: volume>paths ( string -- array ) - [ (volume>paths) ] curry - [ - dup { [ windows-error? ] [ n>> ERROR_FILE_NOT_FOUND = ] } 1&& - [ drop { } ] [ rethrow ] if - ] recover ; +: volume>paths ( string -- array/f ) + '[ _ (volume>paths) ] [ + { [ windows-error? ] [ n>> ERROR_FILE_NOT_FOUND = ] } 1&& + ] ignore-error/f ; ! 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. diff --git a/basis/io/monitors/windows/windows.factor b/basis/io/monitors/windows/windows.factor index 434437dddc..4c99ca18c8 100644 --- a/basis/io/monitors/windows/windows.factor +++ b/basis/io/monitors/windows/windows.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. 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.monitors io.pathnames io.ports kernel literals locals make math sequences system threads windows.errors windows.kernel32 @@ -85,8 +85,8 @@ TUPLE: win32-monitor < monitor port ; dup fill-queue (fill-queue-thread) ; : fill-queue-thread ( monitor -- ) - [ dup fill-queue (fill-queue-thread) ] - [ dup already-disposed? [ 2drop ] [ rethrow ] if ] recover ; + '[ _ dup fill-queue (fill-queue-thread) ] + [ already-disposed? ] ignore-error ; M:: windows (monitor) ( path recursive? mailbox -- monitor ) [ diff --git a/basis/listener/listener.factor b/basis/listener/listener.factor index d1cea41e28..12e8b1ebf5 100644 --- a/basis/listener/listener.factor +++ b/basis/listener/listener.factor @@ -1,10 +1,9 @@ ! Copyright (C) 2003, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors colors colors.constants -combinators.short-circuit compiler.units continuations debugger -fry io io.styles kernel lexer literals locals math math.parser -namespaces parser parser.notes prettyprint sequences sets -source-files.errors system vocabs vocabs.loader +USING: accessors colors colors.constants combinators.short-circuit +compiler.units continuations debugger fry io io.styles kernel lexer +locals math math.parser namespaces parser parser.notes prettyprint +sequences sets source-files.errors system vocabs vocabs.loader vocabs.parser ; IN: listener @@ -40,10 +39,8 @@ SYMBOL: handle-ctrl-break [ [ parse-lines ] with-ctrl-break ] with-compilation-unit ; : read-quot-step ( lines -- quot/f ) - [ parse-lines-interactive ] [ - dup error>> unexpected-eof? - [ 2drop f ] [ rethrow ] if - ] recover ; + '[ _ parse-lines-interactive ] + [ error>> unexpected-eof? ] ignore-error/f ; : read-quot-loop ( stream accum -- quot/f ) over stream-readln dup [ diff --git a/extra/couchdb/couchdb.factor b/extra/couchdb/couchdb.factor index 0de1cb95b8..15db1920e1 100644 --- a/extra/couchdb/couchdb.factor +++ b/extra/couchdb/couchdb.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2008, 2009 Alex Chapman ! 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 json.writer kernel locals make math math.parser namespaces sequences -strings urls urls.encoding vectors ; +strings urls.encoding vectors ; IN: couchdb ! NOTE: This code only works with the latest couchdb (0.9.*), because old @@ -111,9 +111,7 @@ C: db f swap db-url couch-put response-ok* ; : ensure-db ( db -- ) - [ create-db ] [ - dup file-exists-error? [ 2drop ] [ rethrow ] if - ] recover ; + '[ _ create-db ] [ file-exists-error? ] ignore-error ; : delete-db ( db -- ) db-url couch-delete drop ; -- 2.34.1