Clojure

error message for (clojure.java.io/reader nil) — consistency for use with io/resource

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.5
  • Fix Version/s: Release 1.8
  • Component/s: None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

This seems to be a common idiom:

(clojure.java.io/reader (clojure.java.io/resource "myfile"))

When a file is available these are the behaviors:

=> (clojure.java.io/reader "resources/myfile")
#<BufferedReader java.io.BufferedReader@1f291df0>

=> (clojure.java.io/resource "myfile")
#<URL file:/project/resources/myfile>

=> (clojure.java.io/reader (clojure.java.io/resource "myfile"))
#<BufferedReader java.io.BufferedReader@1db04f7c>

If the file (resource) is unavailable:

=> (clojure.java.io/reader "resources/nofile")
FileNotFoundException resources/nofile (No such file or directory)  java.io.FileInputStream.open (FileInputStream.java:-2)

=> (clojure.java.io/resource "nofile")
nil

=> (clojure.java.io/reader (clojure.java.io/resource "nofile"))
IllegalArgumentException No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil  clojure.core/-cache-protocol-fn (core_deftype.clj:541)
;; EXPECTED: better error type/message

This situation would be improved with a better error message from `(clojure.java.io/reader nil)`.

Approach: Extend IOFactory to nil, providing error messages consistent with the default error messages provided for Object.

After:

user=> (clojure.java.io/reader (clojure.java.io/resource "nofile"))
IllegalArgumentException Cannot open <nil> as a Reader.  clojure.java.io/fn--9213 (io.clj:290)

Patch: clj-1210-2.patch

  1. clj-1210-2.patch
    09/Oct/15 9:03 AM
    2 kB
    Alex Miller
  2. extend-io-factory-to-nil.diff
    14/Feb/14 3:13 PM
    2 kB
    Alexander Redington

Activity

Alex Miller made changes -
Field Original Value New Value
Labels errormsgs
Alex Miller made changes -
Labels errormsgs errormsgs io
Alexander Redington made changes -
Attachment extend-io-factory-to-nil.diff [ 12796 ]
Alexander Redington made changes -
Patch Code and Test [ 10002 ]
Alex Miller made changes -
Approval Triaged [ 10120 ]
Alex Miller made changes -
Priority Minor [ 4 ] Major [ 3 ]
Alex Miller made changes -
Description This seems to a common idiom:

    (clojure.java.io/reader (clojure.java.io/resource "myfile"))


When a file is available these are the behaviors:

    => (clojure.java.io/reader "resources/myfile")
    #<BufferedReader java.io.BufferedReader@1f291df0>

    => (clojure.java.io/resource "myfile")
    #<URL file:/project/resources/myfile>

    => (clojure.java.io/reader (clojure.java.io/resource "myfile"))
    #<BufferedReader java.io.BufferedReader@1db04f7c>


If the file (resource) is unavailable:

    => (clojure.java.io/reader "resources/nofile")
    FileNotFoundException resources/nofile (No such file or directory) java.io.FileInputStream.open (FileInputStream.java:-2)

    => (clojure.java.io/resource "nofile")
    nil

    => (clojure.java.io/reader (clojure.java.io/resource "nofile"))
    IllegalArgumentException No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil clojure.core/-cache-protocol-fn (core_deftype.clj:541)


The main enhancement request is to have a better error message from `(clojure.java.io/reader nil)`. I'm not sure if io/resource should return something like 'resource "nofile" not found' or if io/reader could add a more helpful suggestion.
This seems to be a common idiom:

{code}
(clojure.java.io/reader (clojure.java.io/resource "myfile"))
{code}


When a file is available these are the behaviors:

{code}
=> (clojure.java.io/reader "resources/myfile")
#<BufferedReader java.io.BufferedReader@1f291df0>

=> (clojure.java.io/resource "myfile")
#<URL file:/project/resources/myfile>

=> (clojure.java.io/reader (clojure.java.io/resource "myfile"))
#<BufferedReader java.io.BufferedReader@1db04f7c>
{code}

If the file (resource) is unavailable:

{code}
=> (clojure.java.io/reader "resources/nofile")
FileNotFoundException resources/nofile (No such file or directory) java.io.FileInputStream.open (FileInputStream.java:-2)

=> (clojure.java.io/resource "nofile")
nil

=> (clojure.java.io/reader (clojure.java.io/resource "nofile"))
IllegalArgumentException No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil clojure.core/-cache-protocol-fn (core_deftype.clj:541)
;; EXPECTED: better error type/message
{code}

The main enhancement request is to have a better error message from `(clojure.java.io/reader nil)`.

*Approach:* Extend IOFactory to nil, providing error messages consistent with the default error messages provided for Object. After:

{code}
user=> (clojure.java.io/reader (clojure.java.io/resource "nofile"))
IllegalArgumentException Cannot open <nil> as a Reader. clojure.java.io/fn--9213 (io.clj:290)
{code}

*Patch:* extend-io-factory-to-nil.diff
Labels errormsgs io errormsgs ft io
Andy Fingerhut made changes -
Labels errormsgs ft io checkargs errormsgs ft io
Rich Hickey made changes -
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Fix Version/s Release 1.8 [ 10254 ]
Alex Miller made changes -
Description This seems to be a common idiom:

{code}
(clojure.java.io/reader (clojure.java.io/resource "myfile"))
{code}


When a file is available these are the behaviors:

{code}
=> (clojure.java.io/reader "resources/myfile")
#<BufferedReader java.io.BufferedReader@1f291df0>

=> (clojure.java.io/resource "myfile")
#<URL file:/project/resources/myfile>

=> (clojure.java.io/reader (clojure.java.io/resource "myfile"))
#<BufferedReader java.io.BufferedReader@1db04f7c>
{code}

If the file (resource) is unavailable:

{code}
=> (clojure.java.io/reader "resources/nofile")
FileNotFoundException resources/nofile (No such file or directory) java.io.FileInputStream.open (FileInputStream.java:-2)

=> (clojure.java.io/resource "nofile")
nil

=> (clojure.java.io/reader (clojure.java.io/resource "nofile"))
IllegalArgumentException No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil clojure.core/-cache-protocol-fn (core_deftype.clj:541)
;; EXPECTED: better error type/message
{code}

The main enhancement request is to have a better error message from `(clojure.java.io/reader nil)`.

*Approach:* Extend IOFactory to nil, providing error messages consistent with the default error messages provided for Object. After:

{code}
user=> (clojure.java.io/reader (clojure.java.io/resource "nofile"))
IllegalArgumentException Cannot open <nil> as a Reader. clojure.java.io/fn--9213 (io.clj:290)
{code}

*Patch:* extend-io-factory-to-nil.diff
This seems to be a common idiom:

{code}
(clojure.java.io/reader (clojure.java.io/resource "myfile"))
{code}

When a file is available these are the behaviors:

{code}
=> (clojure.java.io/reader "resources/myfile")
#<BufferedReader java.io.BufferedReader@1f291df0>

=> (clojure.java.io/resource "myfile")
#<URL file:/project/resources/myfile>

=> (clojure.java.io/reader (clojure.java.io/resource "myfile"))
#<BufferedReader java.io.BufferedReader@1db04f7c>
{code}

If the file (resource) is unavailable:

{code}
=> (clojure.java.io/reader "resources/nofile")
FileNotFoundException resources/nofile (No such file or directory) java.io.FileInputStream.open (FileInputStream.java:-2)

=> (clojure.java.io/resource "nofile")
nil

=> (clojure.java.io/reader (clojure.java.io/resource "nofile"))
IllegalArgumentException No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil clojure.core/-cache-protocol-fn (core_deftype.clj:541)
;; EXPECTED: better error type/message
{code}

This situation would be improved with a better error message from `(clojure.java.io/reader nil)`.

*Approach:* Extend IOFactory to nil, providing error messages consistent with the default error messages provided for Object.

After:
{code}
user=> (clojure.java.io/reader (clojure.java.io/resource "nofile"))
IllegalArgumentException Cannot open <nil> as a Reader. clojure.java.io/fn--9213 (io.clj:290)
{code}

*Patch:* clj-1210-2.patch
Attachment clj-1210-2.patch [ 15205 ]
Alex Miller made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (4)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: