Closed jdjohnston closed 2 months ago
What's the error your getting, just out of curiosity? Can you paste a stack trace?
@borkdude my laptop is currently offline, but I can provide a verbal stack trace.
str/split-lines
in parse-script
errs with a NullPointerException
because read-header
returns a nil
for a 0-length file. read-header
returns a nil
because .read
returns -1
, which isn't a nat-int?
.
Arguably, a cleaner fix might be to change read-header
from (when (nat-int? n) ...)
to (if (nat-int? n) ... "")
, so that it always returns a string, even for a 0-length file.
BTW, I wish the JVM Clojure stack traces were as user-friendly as Babashka's. Well done. :)
@jdjohnston Nice! Since you analyzed the root cause, perhaps you're willing to put a PR together? If not, I'll get it sooner or later!
I took a look at this issue and don't see why read-header has the (when (nat-int? n) ..)
condition. You can create a string like this: (String. (byte-array (range 1000)) 0 0)
which is just an empty string. Can we remove the condition @rads?
That sounds good to me. 👍
Don't forget, .read
returns -1
when the file is 0-length. (Conflating
0-length with EOF?)
On Fri, Aug 23, 2024, 14:30 Radford Smith @.***> wrote:
That sounds good to me. 👍
— Reply to this email directly, view it on GitHub https://github.com/babashka/bbin/issues/88#issuecomment-2307603716, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4V3RNQ4BEAOU6QNZBLWXLZS55UNAVCNFSM6AAAAABMVTGI3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXGYYDGNZRGY . You are receiving this because you were mentioned.Message ID: @.***>
@borkdude , @rads How about replace when
expression with (String. buffer 0 (max 0 n))
?
n
will be one of three values:
-1
=> 0-length filebuffer
=> file size >=
buffer
size<
buffer
size => file size >
0
and file size <
buffer
sizeSorry, I got a little overwhelmed with other issues. Feel free to submit a PR if you'd like
@jdjohnston Perhaps you're able to test now that I've merged this
@borkdude Works for me after I remembeed to bb gen-script
. Your fix is different than either of my suggestions :), but it works fine.
I suppose gen-script
will be executed for the next release. Am I understanding the workflow correctly?
BTW, I do understand it is better to fix a root-cause than to "band-aid" a symptom. Thanks for the reminder. Next time, feel free to be more blunt. It won't hurt my feelings. :)
Returning an empty string was one of your suggestions right?
Published as 0.2.4
@borkdude I was largely joking. Absolutely no criticism intended. There are probably even more ways to return an empty string. If I truly wanted it done in a certain way, I should have made more effort to generate a PR.
It works. That's the important part.
Why would the bin have a 0-length file? I don't know about others, but I use 0-length files, .e.g.
.notar
, as flags in my dirs.It's an easy fix. Add something like
(> (fs/size %) 0)
to the file filter inload-scripts
(currently line 1510 inbbin
). The change worked fine for me on a local copy ofbbin
.Thanks for this cool util!