What are some easy-to-solve errors you spent awhile fixing?
I just spent an hour searching for how I could have gotten an
Uncaught TypeError: Cannot set properties of null
javascript. I checked the spelling of the element whose property I was trying to set and knew that element wasn't null because the spelling was the same in the code as in the HTML. I also knew my element was loading, so it wasn't that either.
Turns out no, the element was null. I was trying to set " NameHere" when the element's actual name was "NameHere".
Off by a single space. No wonder I thought the spelling was the same—because all the non-whitespace was identical. (No, the quotation marks slanting in the second NameHere and being totally vertical in the first NameHere wasn't a part of the error, I am typing them all vertical and either Lemmy or my instance is "correcting" them to slanted for the second NameHere. But that is also another tricky-to-spot text difference to watch out for!)
And what did not help is that everywhere I specifically typed things out, I had it correct with no extra spaces. Trying to set " NameHere" was the result of modifying a bunch of correct strings, remembering to account for a comma I put between them, but not remembering to account for the space I added after the comma. In short, I only ever got to see " NameHere" written out in the debugger (which is how I caught it after like 30 repeats of running with the debugger), because everywhere I had any strings written out in the code or the HTML it was always written "NameHere".
I figured I'd post about it here in case I can help anyone else going crazy over an error they did not expect and cannot figure out. Next time I get a similar error I will not just check spelling, I'll check everything in the name carefully, especially whitespace at the beginning and end, or things one space apart being written with two spaces instead. Anyone else have a similar story to save the rest of us some time?
When cd drives first came out I got one and then wrote my own program in assembly to display all the information about the drive and disc that you normally can't see (because it was just drive E: or whatever to DOS/Windows).
I named the program cd. It took me way too long to figure out my mistake.
I mean, that's kind of the first big lesson you learn from experience, to put as little trust in humans as possible. My immediate thought was whether one could've put that name into a constant somewhere, so you only had to spell it correctly once or twice.
Frankly, that also kind of makes it difficult for me to answer your question, because when I fuck up like that, I don't remember it as a dumb mistake that I shouldn't do next time, but rather I see it as an indicator that my precautions against human errors aren't good enough. They shouldn't be easy-to-solve, they should be medium-difficult-to-never-see-them-again.
I actually wrote it just once. It acquired the space like this:
I concatenate a bunch of strings together, and add a comma and space between them so I could get stringOne, stringTwo, stringThree etc. I later need to decompose that. I remembered I separated stuff with a comma, but forgot about the space following the comma and that is how I ended up having to deal with " NameHere" vs "NameHere" without having actually written NameHere several times in my code. Is there a better way to go about this?
I have also just read my post again and it explicitly contradicts "I actually wrote it just once". Not sure if I did write it multiple times and merely forgot as I typed this comment and claimed to write it just once, or if I just pretended I wrote it multiple times when it was only once so I could simplify explaining my problem. For the purpose of my question though, let us pretend I did write it once. I promise I am aware that strings that are frequently used should be made constant, although I could use more specifics on what "frequently used" is (more than once?) and I'm wondering if you actually should not really use strings at all and always go for constants.
I spent three days trying to get a RaycastCommand (Unity's jobified raycasts) working to get multiple hits per raycast. Should have been easy, according to the docs:
The result for a command at index N in the command buffer will be stored at index N * maxHits in the results buffer.
If maxHits is larger than the actual number of results for the command the result buffer will contain some invalid results which did not hit anything. The first invalid result is identified by the collider being null
maxHits The maximum number of Colliders the ray can hit
Well, no. I was getting super weird results and couldn't get it to work properly. First thing I checked was if I'm getting two+ hits for any of the raycasts, because you simply can't trust Unity. And I was getting multi hits, but seemingly at random.
The error? I was sorting the hits by distance using bubblesort, and made a simple error with index in it. Which resulted in me seemingly getting two hits per ray sometimes, but it was just a result for another ray moved there by faulty bubblesort. Because unity actually doesn't support multiple hits per ray.
I couldn't find the original thread about the issue (which was two years old by the time I was dealing with it), which had an amazing reply from Unity:
I have discussed it with an engineering team, and RaycastCommands don't support multiple hits because it was difficult to implement. The documentation just doesn't explains it really well
The fuck doesn't explain it very well??? It literally describes a parameter that sets max hits per ray and tells you how to get the multi hits from results...
Number overflow. It happens when you're backend send big number ID serialized in a JSON. The solution is to wrap the number into a string when you know that can happens.
That's one of the things I really like about ruby. You can use p blah instead of puts blah and it will output the actual object structure rather than just the string impl. So for example: