4
b2plane
1y

Spent 3 hours trying to debug why java threw null exception when user disconnects or connects to room id to chat. Guess where the fucking bug was

Comments
  • 1
    you can't use a dash in a parameter?
  • 0
  • 1
    @b2plane don't know then, I don't know java at all
  • 1
    is that even Java? looks (feels?) like Kotlin somehow
  • 4
    @azuredivay Don't insult my Kotlin please 😉 That's JS (or possibly TS) react code.
  • 0
    username or roomId null?
  • 0
    @cb219 i put question mark `?` and it wasn't supposed to be put because the `query` attribute adds it automatically. as if i was supposed to know that
  • 2
    @b2plane why do u include me in that, never mentioned react in this thread :p
  • 0
    @We3D cz u mentioned java and this has nothing to do with java
  • 5
    @b2plane soo, tell me why you wrote '...why java threw...' then
  • 5
    @b2plane U SAID "JAVA" BOI :v
  • 4
    Java is to Javascript as car is to carpet :P
  • 4
    @b2plane

    You went with socket.Io. Deal with cancer. (Or better, learn real sockets. Or, as this seems web, real websockets.)

    A quick glimpse at the URL spec would have told you that the "?" Is a separator and not part of the query string.

    You explicitly mentioned java.
  • 5
    I upvoted this rant to keep it visible, shaming its creator.
  • 1
    I hope you have a really good reason to assign event handlers to a stateful networking primitive inside a UI component.
  • 1
    @AleCx04 they're both for transportation but the carpet doesn't have blinkers
  • 1
    @b2plane please stop calling your js shit java, thanks
  • 0
    @azuredivay got too lazy to write a detailed caption, i meant the backend (built in java) threw exception because of this frontend (built in react) code
  • 0
    So the frontend called the server with an url including TWO questionMarks and that caused a server error?

    Feels like if the server request handler was set up nicely this would result in a "bad request" error or something like that indicating the url was malformed
  • 1
    Concatting strings into a URL is a common source of mistakes

    In plain JS it's made slightly less prone to mistakes if you'd use the native URL object with its searchParams attribute to do something like

    const url = new URL(baseUrl); url.searchParams.add("username", username); url.searchParams.add("room-id", roomId);

    To get the full adress you'd use
    url.toString();

    Allthough I'm not entirely happy with the URL or URLSearchParams objects as I would've liked to be able to use them as a one liner with an array Input. Using an append-fn for every param makes it too wordy. and if you don't you still have to remeber to put the & between params
  • 1
    @lorentz
    1. I took this code from someone elses github
    2. Im not a react expert so i have no idea how useEffect works under the hood
    3. This code works fine
  • 0
    @jiraTicket new URLSearchParams({ username, roomId })
  • 0
    @devRancid ooooh thanks.
Add Comment