Urgent.News

What's breaking now, across thousands of outlets.

Tech

A client you can still use when you configured it wrong

There's a question that turns up every time you wire a chat client together, and it's this. You set a temperature. The model you picked doesn't do temperature. Now what? It's a fair question, and Go has a very firm opinion about it. I disagree with Go. Go wants a yes or a no The constructor convention is about as settled as conventions get: return (T, error) , and on a non-nil error the T is…

Every time you wire a chat client together, a question arises: you set a temperature, but the chosen model doesn't support it. Go has a clear stance on this matter, favoring a yes or no response. The constructor convention is widely accepted, following a return (T, error) pattern. When an error occurs, the T is no longer usable.

This approach assumes construction either succeeded or failed entirely, such as opening a file, dialing a socket, or parsing a document. A chat client, however, is made up of various components like providers, models, credentials, timeouts, endpoints, sampling controls, streaming, tool support, fallback chains, and numerous customizable options.

Constructing such a client involves making multiple small decisions, and when one fails, the impact is often partial. Most of these components work fine, but the one that doesn't, usually the least important one, remains unchanged. The binary outcome doesn't offer a clear indication of what went wrong, so the library resorts to two undesirable outcomes: either accepting a malfunctioning client or concealing the issue, leading users to believe it applies universally.

To address this, a new approach is proposed. If you build a client with an invalid combination, instead of discarding the entire client, you receive a working version with the functional parts intact, accompanied by a detailed list of what couldn't be applied. This error message not only identifies the dropped setting but also explains why it happened.

The structure includes the name of the dropped setting, the required capability, and a concise explanation of the reason behind the failure. This detailed error message empowers developers to rectify the issue effectively. By providing a comprehensive receipt, the design ensures that developers have all the necessary information to troubleshoot and resolve the problem.

While some argue against this approach, claiming that it might confuse callers who ignore the error details, the strict contract ultimately protects users from encountering a completely broken client. The focus is on delivering a complete, specific, and actionable error message, empowering developers to take appropriate actions rather than silently swallowing errors.

Although this design shifts the decision-making responsibility from the library to the caller, it still safeguards against the worst-case scenario of a completely malfunctioning client.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Writing a real PNG compressor in vanilla JavaScript (no WASM, no libraries)

Every online image converter I tried had the same shape: drag your file in, it uploads to a server somewhere, you get a download link back. That's fine for a meme.

  • Vanilla JavaScript PNG compressor created without WASM or libraries
  • canvas.toBlob() method can silently generate incorrect PNG files
  • Manual compression required to achieve significant file size reduction

More from Thursday 17 September →