Clojure

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

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.5
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Triaged

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.

Activity

Hide
Alexander Redington added a comment -

This patch extends IOFactory to nil, providing error messages consistent with the default error messages provided for Object.

Show
Alexander Redington added a comment - This patch extends IOFactory to nil, providing error messages consistent with the default error messages provided for Object.
Hide
Benjamin Peter added a comment - - edited

Looks like a good solution to me as a user. Thanks for the effort!

Show
Benjamin Peter added a comment - - edited Looks like a good solution to me as a user. Thanks for the effort!
Hide
Dennis Schridde added a comment -

I would also be interested in a solution, as I am currently running into this with the ClojureScript compiler.

Show
Dennis Schridde added a comment - I would also be interested in a solution, as I am currently running into this with the ClojureScript compiler.

People

Vote (3)
Watch (4)

Dates

  • Created:
    Updated: