-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clj-commons/fs
changes standard clojure behaviour in clojure.java.io/file
#355
Comments
Thanks! Will check if refactor-nrepl actually does use this extension in any way. If not, I might fork the dep and remove the extension. |
Just stating the obvious, by using profiles/aliases, refactor-nrepl should never be included in a release build. Similarly, most behavior should be captured by unit tests, which also should not include refactor-nrepl in a CI environment. (Some people still don't realise the value of a strict separation between |
clojure.java.io/file
clj-commons/fs
changes standard clojure behaviour in clojure.java.io/file
Thanks! Another alternative hack would be to rebind the extensions immediately after ;; undo clj-common/fs extension
(extend-protocol clojure.java.io/Coercions
java.nio.file.Path
(as-file [this] (throw (IllegalArgumentException. (str "No implementation of method: "
:as-file
" of protocol: " (var clojure.java.io/Coercions)
" found for class: " 'java.nio.file.Path))))
(as-url [this] (throw (IllegalArgumentException. (str "No implementation of method: "
:as-url
" of protocol: " (var clojure.java.io/Coercions)
" found for class: " 'java.nio.file.Path))))
)
user> (-> "a-path" (java.nio.file.Paths/get (into-array String [])) clojure.java.io/file)
Execution error (IllegalArgumentException) at eval19905$fn (REPL:25).
No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: java.nio.file.Path
user> (-> "a-path" (java.nio.file.Paths/get (into-array String [])) clojure.java.io/as-url)
Execution error (IllegalArgumentException) at eval19905$fn (REPL:29).
No implementation of method: :as-url of protocol: #'clojure.java.io/Coercions found for class: java.nio.file.Path
;; with original exception for unsupported types being
user> (clojure.java.io/as-file [])
Execution error (IllegalArgumentException) at user/eval19919 (REPL:133).
No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.PersistentVector But I am not sure how this would play out with Mr. Anderson inlining the namespace.
I agree on both counts. It so happens that particular library is in early stages of development and does not have a test suite published yet. Thus I am at the mercy of testing the behaviour via the REPL. Btw, I've noticed that ;;;###autoload
(eval-after-load 'cider
'(cljr--inject-jack-in-dependencies)) would you consider a PR to inject the middlewares only when the minor mode is on? Thanks! |
Nice! Will consider.
Each refactor-nrepl functionality is lazily loaded; it doesn't slow down startup time unless/until a specific feature is used. You can learn about it here: refactor-nrepl/src/refactor_nrepl/middleware.clj Lines 128 to 147 in da81035
Given this laziness, further optimizing things has diminishing returns - it's simpler to focus simply on the JVM side instead of having to coordinate our 'backend' and 'frontend'. Cheers - V |
It does indeed :) I was more concerned about the case where the user installed the
thanks again! |
IDK, we're tallking about a pretty extreme corner case here. The expectation is that if you have clj-refactor installed / set up, you will use it. One typically doesn't enable modes 'by hand'. One might even use it without realising. If there's a specific problem, feel free to open it as an issue (if it's this one i.e. the |
These allow dependent libraries to use `fs` without the side-effect of extend. Otherwise one can unawarely create issues, as seen in https://github.com/clojure-emacs/clj-refactor.el/issues/508. https://clojure.org/reference/protocols#_guidelines_for_extension says: > If you don’t own the protocol or the target type, you should only extend in app (not public lib) code, and expect to maybe be broken by either owner.
These allow dependent libraries to use `fs` without the side-effect of extend. Otherwise one can unawarely create issues, as seen in https://github.com/clojure-emacs/clj-refactor.el/issues/508. https://clojure.org/reference/protocols#_guidelines_for_extension says: > If you don’t own the protocol or the target type, you should only extend in app (not public lib) code, and expect to maybe be broken by either owner.
Created clj-commons/fs#11 Transfered the issue to refactor-nrepl as well |
I think we've exhausted the subject, no need for raising another issue. Thanks for looking at the fs 👍🏻 |
`supported-file?` is given a path argument that cannot be coerced into a `java.io.File` unless a coercion is present on the classpath clojure-emacs/refactor-nrepl/issues/355. Co-authored-by: ikappaki <[email protected]> Co-authored-by: Martin Kavalar <[email protected]>
These could affect end-users. Fixes #355
These could affect end-users. Fixes #355
These could affect end-users. Fixes #355
These could affect end-users. Fixes #355
These could affect end-users. Fixes #355
To be released soon, maybe I'll bundle something else while we're there |
Released as 3.2.0 |
Expected behavior
The REPL shouldn't change standard Clojure behaviour, otherwise it might lead to unexpected behaviour in release builds.
Brining up a REPL with clj-refactor installed allows
clojure.java.io/file
to supportjava.nio.file.Path
as an argument, while it does not in the standard core, .e.g. if we bring up a vanilla REPL (wo clj-refactor) and try to open aPath
withio/file
it fails as expected:Analysis follows at the end.
Actual behavior
clj-refactor changes standard Clojure behaviour with regards to opening files with
clojure.java.io/file
.Steps to reproduce the problem
M-x cider-jack-in
to a minimaldeps.edn
file.java.nio.Path
i.e. it returns the file from the
PATH
, while this is unsupported in standard Clojure behaviour.Environment & Version information
clj-refactor.el version information
clj-refactor 3.2.2 (package: 20211117.1008), refactor-nrepl 3.1.0
CIDER version information
Include here the version string displayed when
CIDER's REPL is launched. Here's an example:
Leiningen or Boot version
Emacs version
GNU Emacs 27.2
Operating system
MS-Windows 10
Analysis
The standard supported
io/file
arguments types are defined by theio/Coercions
protocol'sas-file
method and areString
,File
,URL
andURI
.The support for
Path
's inio/file
is brought in by the clj-common/fs dependency addingPath
toio/Coercions
.clj-common/fs
is part ofrefactor-nrepl
middleware injected byclj-refactor
:I was caught off guard with this while providing a PR about filtering filenames given a path and would like to bring this to your attention. Thinking my input path was a
String
I was passing itio/file
with the aim to retrieve its filename with.getName
, but it turned out it was aPath
. It should have failed while I was testing on the REPL before reaching the release build, but it got missed because of this. I even naively thought afterwards thatPath
d were supported in the standard API, but it does not https://clojure.atlassian.net/browse/CLJ-2333.IMHO REPL middleware shouldn't modify standard behaviour since this might lead to confusion with what we are getting during dev vs release. Not exactly sure how to fix this particular issue since this is not part of the middleware core but rather an external dependency, but wanted to open the discussion anyway.
nextjournal/clerk#28
Thanks!
The text was updated successfully, but these errors were encountered: