The developer who came in from the cold and melted a mainframe
Who, Me? The world is rapidly becoming a more uncertain place, but The Register tries to offer readers one small point of certainty by always delivering a fresh Monday morning instalment of "Who, Me?" – the reader-contributed column in which you admit to your errors and elucidate your escapes.…
CodeSOD: The Update Route
Today's anonymous submission is one of the entries where I look at it and go, "Wait, that's totally wrong, that could have never worked." And then I realize, that's why it was submitted: it was absolutely broken code which got to production, somehow.
Collection.updateOne(query, update, function(err, result, next)=>{ if(err) next(err) ... })So, Collection.updateOne is an API method for MongoDB. It takes three parameters: a filter to find the document, an update to perform on the document, and then an object containing other parameters to control how that update is done.
So this code is simply wrong. But it's worse than that, because it's wrong in a stupid way.
When creating routes using ExpressJS, you define a route and a callback to handle the route. The callback takes a few parameters: the request the browser sent, the result we're sending back, and a next function, which lets you have multiple callbacks attached to the same route. By invoking next() you're passing control to the next callback in the chain.
So what we have here is either an absolute brain fart, or more likely, a find-and-replace failure. A route handling callback got mixed in with database operations (which, as an aside, if your route handling code is anywhere near database code, you've also made a horrible mistake). The result is a line of code that doesn't work. And then someone released this non-working code into production.
Our submiter writes:
This blew up our logs today, has been in the code since 2019. I removed it in a handful of other places too.
Which raises the other question: why didn't this blow up the logs earlier?
Jennifer Aniston and boyfriend Jim Curtis snuggle-up in romantic selfie as relationship continues going the distance
I became a first time mum at 46 after spending £70,000 on IVF... my son is one and now I'm broody for a second baby
I'm 73 and a victim of a National Insurance glitch: STEVE WEBB wins thousands of pounds for reader
Branded residences come to Antigua with iconic Nikki Beach heading to the Caribbean island… and homes start at £910,000
Vile domestic abuser headbutted girlfriend and strangled her with phone charger
Poor health means driver won't be charged after crash which killed man in Witham
ANDREW PIERCE: Do Labour know what a child is?
The Morning Poll: Will you use the bank holiday to do some DIY?
Tori Spelling recovers from terrifying car crash that landed family in hospital as she speaks with paramedics in aftermath
Baywatch star Noah Beck's sister accused of grooming her male student and being his 'sugar momma' at quaint hometown high school
Artemis Astronauts Enter Moon's Gravitational Pull, Catch First Glimpses of Far Side
Read more of this story at Slashdot.