ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
notzmv has quit [Ping timeout: 252 seconds]
ur5us_ has joined #crystal-lang
ur5us_ has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
ejjfunky has joined #crystal-lang
notzmv has joined #crystal-lang
waleee has quit [Ping timeout: 260 seconds]
ur5us has quit [Ping timeout: 272 seconds]
taupiqueur has joined #crystal-lang
notzmv has quit [Ping timeout: 240 seconds]
notzmv has joined #crystal-lang
taupiqueur has quit [Ping timeout: 240 seconds]
taupiqueur has joined #crystal-lang
wolfshappen_ has quit [*.net *.split]
void09 has quit [*.net *.split]
rymiel has quit [*.net *.split]
antoszka has quit [*.net *.split]
DeBot has quit [*.net *.split]
Elouin has quit [*.net *.split]
wolfshappen_ has joined #crystal-lang
void09 has joined #crystal-lang
antoszka has joined #crystal-lang
DeBot has joined #crystal-lang
Elouin has joined #crystal-lang
rymiel has joined #crystal-lang
wolfshappen_ has quit [Max SendQ exceeded]
wolfshappen has joined #crystal-lang
Guest60 has joined #crystal-lang
Guest60 has quit [Client Quit]
taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
taupiqueur has quit [Quit: taupiqueur]
notzmv has quit [Ping timeout: 245 seconds]
waleee has joined #crystal-lang
notzmv has joined #crystal-lang
ejjfunky has quit [Ping timeout: 240 seconds]
<SamantazFox> Hello there!
<SamantazFox> I have a weird thing hapenning
<FromGitter> <Blacksmoke16> again? :P
<SamantazFox> yeah xD
<SamantazFox> My tests just hangs
<FromGitter> <Blacksmoke16> step 1, figure out what test is doing it
<FromGitter> <Blacksmoke16> maybe try running each spec file 1 by 1 until it happens?
<SamantazFox> well, I ran `crystal spec <file>` and shaved a lot the tests (basically, 99% is commented out)
<SamantazFox> I know which file is causing it.
<FromGitter> <Blacksmoke16> oh perfect, and whats the code look like?
<SamantazFox> Like that
<SamantazFox> Hmmmm.... I've commented out the `.try` statements in the end, and that makes the test fail
<FromGitter> <Blacksmoke16> know what line it getting stuck at?
<SamantazFox> nope, I'm trying to figure that out
<FromGitter> <Blacksmoke16> see if you can get rid of the custom stuff and see if you can reproduce with just the stdlib code?
<SamantazFox> mmh, yeah.
<SamantazFox> Blacksmoke16: What's the syntax for specs alread? `(statement).should eq(result)`, right?
<FromGitter> <Blacksmoke16> yea
<SamantazFox> And yep, can reproduce with the stlib
<FromGitter> <Blacksmoke16> oh?
<SamantazFox> here's the test file
<FromGitter> <Blacksmoke16> what about the filters file/
<SamantazFox> that's the file I shared 16 mins ago :)
<FromGitter> <Blacksmoke16> oh 👍
<SamantazFox> (you can replace the last return with `return object.to_json.to_s` btw)
<SamantazFox> (that way you don't need the protodec dependency)
<SamantazFox> I'm using crystal 1.3.2
<FromGitter> <Blacksmoke16> all the tests failed for me
<FromGitter> <Blacksmoke16>
<SamantazFox> Failing is normal, because the objects aren't encoded (you don't have protodec)
<SamantazFox> but that's still better than what I'm getting, lol
<FromGitter> <Blacksmoke16> does creating a new file with only that in it also get stuck? or only when running that one spec file within the code base
<SamantazFox> I haven't tried putting everything in one file
<FromGitter> <Blacksmoke16> if that works, could be something in your `spec_helper`
<SamantazFox> Though, that shouldn't change anything, as the functions are independant
<SamantazFox> (and the spec_helper isn't `require`d, so I don't see how it would interfer?)
<FromGitter> <Blacksmoke16> true
<SamantazFox> So, removing the `require "protodec"` made it faile immediately.
<SamantazFox> fail*
<FromGitter> <Blacksmoke16> is that a shard i assume?
<SamantazFox> yep
<FromGitter> <Blacksmoke16> cant really have code that does stuff when required like that
<FromGitter> <Blacksmoke16> use two files, one that defines the lib code and another as an entrypoint into the CLI
<SamantazFox> ok, I found out my problem
<SamantazFox> I had to require `protodec/utils`
<SamantazFox> but the bug is weird nonetheless
<FromGitter> <Blacksmoke16> not really
<FromGitter> <Blacksmoke16> you have code in the top level that is doing `STDIN.gets_to_end`, you're requiring that in your code, and when you run tests there is no STDIN so it blocks waiting for input
<SamantazFox> waiting for input? what input?
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> just run like `crystal eval 'pp STDIN.gets_to_end'`
<FromGitter> <Blacksmoke16> any input
<SamantazFox> I mean, why is it waiting for an input? Shouldn't that raise a compile-time error?
<FromGitter> <Blacksmoke16> how would it raise a compile time error?
<FromGitter> <Blacksmoke16> STDIN is a runtime thing
<FromGitter> <Blacksmoke16> and its waiting because you're telling it to get all the data from that IO, but there is none, so it waits
<SamantazFox> Oh, okay, I see
<SamantazFox> but in my case, I don't see why it hangs like that?
<SamantazFox> the main file of protodec requires the `utils` file
<FromGitter> <Blacksmoke16> right, but all that code to parse data from stdin is on the top level of the main file, so it also runs when its required
<FromGitter> <Blacksmoke16> or at some point when you run the file that requires it*
<SamantazFox> Ahhhhhh, makes sense ^^
<SamantazFox> Now I'm puzzled by that.
<FromGitter> <Blacksmoke16> you `require "json"`?
<SamantazFox> *facepalms*
<SamantazFox> Ok, I thought that the `#to_json` method of a `Hash` was standard (i.e not required to `require` something else)
<FromGitter> <Blacksmoke16> no you need to require json module to get that default to/from json logic
<SamantazFox> ok
<SamantazFox> I'd like the compiler to be smarter sometimes ^^>
<FromGitter> <Blacksmoke16> smarter how? suggest to require that module?
<SamantazFox> yeah, something like that
<FromGitter> <Blacksmoke16> i feel like that would be verryyyyyy tricky
<FromGitter> <Blacksmoke16> as for 1 it wouldnt know what code is in it if you dont require it, plus handling shards/overloads etc
<SamantazFox> like "hmm, `to_json` on a <stdlib type>? maybe they forgot that module"
<SamantazFox> I don't ask something like Rust (their compiler messages are both awefully and incredibly detailed) but maybe some basic logic?
<SamantazFox> (I've never looked at the compiler code, so maybe that's completely unfeasible)
<FromGitter> <Blacksmoke16> but what if another shard also defines `to_json`
<SamantazFox> Well then the error saying that there is no method for <stdlib type> won't be raised
<FromGitter> <Blacksmoke16> but how would it know what methods even are available if its not required
<FromGitter> <Blacksmoke16> idk its an idea, maybe start a forum thread about it and go from there?
<SamantazFox> to/from json/XML are, afaik, the few methods that aren't part of the base type definition (which are always "required"). So it could be easy to check those know cases (of course, it would be impossible to "browse" non-required shards)
ur5us has joined #crystal-lang
<SamantazFox> As for the forum thread, yeah, that's a good idea
<SamantazFox> will do that (I need to make an account first, tho)
<FromGitter> <asterite> What about something like this?
<FromGitter> <asterite> I think if these are very common issues people stumble upon, I wouldn't mind adding that to the standard library. Same for YAML. And even...
<FromGitter> <asterite> Or this:
<FromGitter> <asterite> I think the second one we should definitely do. When you do `require "json"` it defines a `to_json` for all objects, but it only works if you define a `to_json(builder : JSON::Builder)` for a given object. Without that guidance you will probably be lost unless you are familiar with how things work.
<FromGitter> <asterite> Feel free to suggest these things in the forums, github, etc.!
<FromGitter> <asterite> I wonder if Crystal is the only language that lets you produce customized compiler errors... 🤔
<FromGitter> <asterite> Maybe not, it seems Scala also does it
<SamantazFox> asterite: yeah, that's not the way I was expecting it, but that's perfect :D
<SamantazFox> That would honnestly help *a lot*
<SamantazFox> I'm pretty sure it's the kind of basic errors that happen all the time.
<FromGitter> <asterite> I might even open a forum thread about this tomorrow. It might look a bit hacky (why is there a `to_json` method with a custom error message there?) but Crystal is all about being pragmatic, and these kind of errors will be super useful to have
<SamantazFox> I don't see how it's hacky
<FromGitter> <asterite> Well, as George said, if you don't use the standard json library and something else, that error will be misleading. But chances of that happening are low or null in my opinion
<SamantazFox> asterite: In the even where someone uses some other library that declares `#to_json`, then only the "require" name will be wrong. It would still hint the user about a missing `require`.
<FromGitter> <Blacksmoke16> I'm sure you could word craft the message to use it as an example in a more general question
Elouin has quit [Quit: Ping timeout (120 seconds)]
Elouin has joined #crystal-lang
ua_ has quit [Ping timeout: 272 seconds]
ur5us has quit [Ping timeout: 240 seconds]
ua_ has joined #crystal-lang
ua_ has quit [Ping timeout: 256 seconds]
ua_ has joined #crystal-lang