Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Failway is a typescript library for elegant error handling.
It's inspired by the concept of Railway Oriented Programming (ROP).
npm i failway
The worst parts of the code are the parts which handle errors.
Consider the following code from a single page app:
const request = buildRequest();
let response;
try {
response = await fetchData(request);
} catch (networkError) {
showNetworkDisconnectedPopup();
return;
}
if (response.statusCode === 404) {
display404Page();
return;
} else if (response.statusCode === 401) {
displayLogin();
return;
} else if (response.statusCode != 200 ) {
displayErrorPage();
return;
}
let responseData;
try {
responseData = parseData(response);
} catch (parseDataError) {
displayErrorPage();
return;
}
// Do something with the response data
Ugly, right?
The error handling obstructs the true purpose of the procedure - a call to an API.
With ROP we would write it like this:
const result = Rail(requestInfo)
.map(buildRequest)
.map(fetchData)
.map(checkResponseCode)
.map(parseData)
.done()
if (result.status === "OK") {
// do something with response data
return;
} else if (result.status === "NETWORK_ERR") {
showNetworkDisconnectedPopup();
} else if (result.status === "404") {
display404Page();
} else if (result.status === "401") {
displayLogin();
} else {
displayErrorPage();
}
Much cleaner.
ROP allows us to separate the "happy path" from the error handling, thus simplifying the code.
It looks similar (by design), but it provides a few improvements:
result.err
as a union type, so the compiler will check that you handled all of the cases.FAQs
A typescript library for Railway Oriented Programming.
The npm package failway receives a total of 2 weekly downloads. As such, failway popularity was classified as not popular.
We found that failway demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.