Code Explainers
Code explainers tagged #error-handling
rust
use base64::engine::general_purpose::{STANDARD, URL_SAFE_NO_PAD}; use base64::{DecodeError, Engine}; pub fn encode_standard(data: &[u8]) -> String {
Base64 encode and decode in Rust
base64
encoding
error-handling
Beginner
7 steps
rust
use std::collections::HashMap; #[derive(Debug)] pub struct RequestHead {
Parsing an HTTP request head in Rust
parsing
error-handling
iterators
Intermediate
9 steps
go
package humanize import ( "fmt"
Parsing human-readable byte sizes in Go
parsing
regex
lookup-table
Intermediate
8 steps
ruby
class TemplateInterpolator PLACEHOLDER = /\{\{\s*([\w.]+)\s*\}\}/ def initialize(strict: false)
Interpolating templates with dotted keys in Ruby
regex
string-interpolation
hash-traversal
Intermediate
6 steps
go
package config import ( "fmt"
A thread-safe config singleton in Go
singleton
concurrency
environment-variables
Intermediate
7 steps
rust
use std::net::Ipv4Addr; use std::str::FromStr; #[derive(Debug, Clone, Copy)]
Parsing and matching IPv4 CIDR ranges in Rust
bitwise-operations
parsing
error-handling
Intermediate
8 steps
typescript
import { parsePhoneNumberFromString, CountryCode } from 'libphonenumber-js'; export interface NormalizedPhone { e164: string;
Normalizing phone numbers to E.164 in TypeScript
validation
normalization
error-handling
Intermediate
7 steps
ruby
require "timeout" require "net/http" class RemoteInventoryClient
Bounding a slow HTTP call with Timeout in Ruby
timeout
error-handling
http
Intermediate
6 steps
rust
use std::sync::mpsc; use std::thread; use std::time::Duration;
Running work with a timeout in Rust
concurrency
channels
timeout
Intermediate
7 steps
ruby
require "yaml" class FrontMatter DELIMITER = /\A---\s*\n(.*?)\n---\s*\n?(.*)\z/m
Parsing YAML front matter in Ruby
parsing
regular-expressions
yaml
Intermediate
8 steps
rust
use axum::{extract::State, response::IntoResponse, Json}; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use std::sync::Arc;
Building a JSON-RPC 2.0 handler in Axum
json-rpc
serde
request-dispatch
Intermediate
8 steps
python
import signal import time import logging
Graceful shutdown in a queue worker
signals
graceful-shutdown
message-queue
Intermediate
7 steps
rust
use std::collections::BTreeSet; use std::fs::File; use std::io::{self, BufRead, BufReader, BufWriter, Write}; use std::path::Path;
Deduplicating and sorting words in Rust
file-io
btreeset
string-processing
Intermediate
6 steps
ruby
module Authenticatable extend ActiveSupport::Concern included do
JWT authentication as a Rails concern
authentication
jwt
concerns
Intermediate
6 steps
rust
use axum::{ http::{header, StatusCode}, response::{IntoResponse, Response}, Json,
Turning errors into RFC 7807 responses in Axum
error-handling
enums
trait-implementation
Intermediate
7 steps
php
<?php namespace App\Jobs;
A retrying queue job in Laravel
queues
background-jobs
retries
Intermediate
7 steps
ruby
module AppConfig module_function def fetch(key, default: nil, required: false)
Typed environment variable config in Ruby
environment-variables
type-coercion
configuration
Intermediate
7 steps
typescript
interface JwtPayload { exp?: number; iat?: number; sub?: string;
Decoding a JWT to check expiry
jwt
base64url
type-guards
Intermediate
8 steps