Computer
Three-Quarters of Countries Face Below-Replacement Fertility by 2050
Read more of this story at Slashdot.
Gates Funds $1 Million AI Alzheimer's Prize
Read more of this story at Slashdot.
MIT Report: 95% of Generative AI Pilots at Companies Are Failing
Read more of this story at Slashdot.
UK is Lagging Behind Rest of World in Tackling Big Tech, Says Fortnite Chief
Read more of this story at Slashdot.
US FTC Sues Ticket Reseller For Evading Taylor Swift's Eras Tour Ticket Limits
Read more of this story at Slashdot.
CodeSOD: I Am Not 200
In theory, HTTP status codes should be easy to work with. In the 100s? You're doing some weird stuff and breaking up large requests into multiple sub-requests. 200s? It's all good. 300s? Look over there. 400s? What the hell are you trying to do? 500s? What the hell is the server trying to do?
This doesn't mean people don't endlessly find ways to make it hard. LinkedIn, for example, apparently likes to send 999s if you try and view a page without being logged in. Shopify has invented a few. Apache has added a 218 "This is Fine". And then there's WebDAV, which not only adds new status codes, but adds a whole bunch of new verbs to HTTP requests.
Francesco D sends us a "clever" attempt at handling status codes.
try { HttpRequest.Builder localVarRequestBuilder = {{operationId}}RequestBuilder({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}headers); return memberVarHttpClient.sendAsync( localVarRequestBuilder.build(), HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> { if (localVarResponse.statusCode()/ 100 != 2) { return CompletableFuture.failedFuture(getApiException("{{operationId}}", localVarResponse)); } {{#returnType}} try { String responseBody = localVarResponse.body(); return CompletableFuture.completedFuture( responseBody == null || responseBody.isBlank() ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference<{{{returnType}}}>() {}) ); } catch (IOException e) { return CompletableFuture.failedFuture(new ApiException(e)); } {{/returnType}} {{^returnType}} return CompletableFuture.completedFuture(null); {{/returnType}} }); }Okay, before we get to the status code nonsense, I first have to whine about this templating language. I'm generally of the mind that generated code is a sign of bad abstractions, especially if we're talking about using a text templating engine, like this. I'm fine with hygienic macros, and even C++'s templating system for code generation, because they exist within the language. But fine, that's just my "ok boomer" opinion, so let's get into the real meat of it, which is this line:
localVarResponse.statusCode()/ 100 != 2"Hey," some developer said, "since success is in the 200 range, I'll just divide by 100, and check if it's a 2, helpfully truncating the details." Which is fine and good, except neither 100s nor 300s represent a true error, especially because if the local client is doing caching, a 304 tells us that we can used the cached version.
For Francesco, treating 300s as an error created a slew of failed requests which shouldn't have failed. It wasn't too difficult to detect- they were at least logging the entire response- but it was frustrating, if only because it seems like someone was more interested in being clever with math than actually writing good software.
[Advertisement] Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.US Spy Chief Gabbard Says UK Agreed To Drop 'Backdoor' Mandate for Apple
Read more of this story at Slashdot.
OpenAI Launches $4.6 Budget AI Subscription Tier in India
Read more of this story at Slashdot.
Intel is Getting a $2 Billion Investment From SoftBank
Read more of this story at Slashdot.
Why Did Hollywood Stop Making Comedies? A Statistical Analysis
Read more of this story at Slashdot.
Fujifilm Announces Second US Price Increase in August
Read more of this story at Slashdot.
How Can England Possibly Be Running Out of Water?
Read more of this story at Slashdot.
AI 'Business Agents' Will Kill SaaS by 2030, Says Microsoft
Read more of this story at Slashdot.
Gamblers Now Bet on AI Models Like Racehorses
Read more of this story at Slashdot.
LinkedIn Is the Fakest Platform of Them All
Read more of this story at Slashdot.
'The One Feature That Keeps Me From Recommending Flip Phones'
Read more of this story at Slashdot.
Wikipedia Volunteer Uncovers Decade-Long Campaign That Created 335 Articles About One Composer
Read more of this story at Slashdot.
5% of Americans are Cancer Survivors - and They're Living Longer
Read more of this story at Slashdot.
Male-Oriented App 'TeaOnHer' Also Had Security Flaws That Could Leak Men's Driver's License Photos
Read more of this story at Slashdot.
CodeSOD: Going Crazy
For months, everything at Yusuf's company was fine. Then, suddenly, he comes in to the office to learn that overnight the log exploded with thousands of panic messages. No software changes had been pushed, no major configurations had happened- just a reboot. What had gone wrong?
This particular function was invoked as part of the application startup:
func (a *App) setupDocDBClient(ctx context.Context) error { docdbClient, err := docdb.NewClient( ctx, a.config.MongoConfig.URI, a.config.MongoConfig.Database, a.config.MongoConfig.EnableTLS, ) if err != nil { return nil } a.DocDBClient = docdbClient return nil }This is Go, which passes errors as part of the return. You can see an example where docdb.NewClient returns a client and an err object. At one point in the history of this function, it did the same thing- if connecting to the database failed, it returned an error.
But a few months earlier, an engineer changed it to swallow the error- if an error occurred, it would return nil.
As an organization, they did code reviews. Multiple people looked at this and signed off- or, more likely, multiple people clicked a button to say they'd looked at it, but hadn't.
Most of the time, there weren't any connection issues. But sometimes there were. One reboot had a flaky moment with connecting, and the error was ignored. Later on in execution, downstream modules started failing, which eventually lead to a log full of panic level messages.
The change was part of a commit tagged merely: "Refactoring". Something got factored, good and hard, all right.
[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.