Code Explainers
Code explainers tagged #error-handling
ruby
require "csv" def parse_transaction_row(line) fields = CSV.parse_line(line, headers: false, skip_blanks: true)
Parsing one CSV transaction row in Ruby
parsing
type-coercion
error-handling
Intermediate
6 steps
java
@RestController @RequestMapping("/api/quotes") public class QuoteStreamController {
Streaming market quotes with Spring WebFlux
reactive-streams
backpressure
server-sent-events
Advanced
9 steps
rust
use std::collections::HashMap; use std::fs::File; use std::io::{self, BufRead, BufReader}; use std::path::Path;
Parsing INI files in Rust
parsing
file-io
hashmap
Intermediate
9 steps
python
from pathlib import Path from PIL import Image, ImageOps
Batch image resizing with Pillow
image-processing
batch-jobs
error-handling
Intermediate
8 steps
go
package handler type LineItem struct { SKU string `json:"sku" binding:"required,alphanum"`
Structured validation errors in Gin
validation
json-binding
error-handling
Intermediate
8 steps
javascript
import { useState, useCallback, useRef } from 'react'; function LikeButton({ postId, initialLiked, initialCount }) { const [liked, setLiked] = useState(initialLiked);
Optimistic like button with React
optimistic-ui
abortcontroller
error-handling
Advanced
7 steps
php
public function transaction(callable $callback, int $maxAttempts = 3): mixed { $attempt = 0;
Retrying database deadlocks in PHP
retry
transactions
deadlock
Intermediate
8 steps
rust
use std::time::Duration; #[derive(Debug, Clone)] pub struct ServerConfig {
The builder pattern in Rust
builder-pattern
ownership
error-handling
Intermediate
8 steps
go
func ProxyDownload(c *gin.Context) { objectKey := c.Param("key") upstream := fmt.Sprintf("%s/files/%s", storageBaseURL, objectKey)
Streaming a proxied download in Gin
reverse-proxy
streaming
http-headers
Intermediate
8 steps
rust
use std::time::Duration; use axum::{ extract::State,
Rate-limit errors as Axum responses
error-handling
rate-limiting
http-headers
Intermediate
6 steps
java
package com.example.payments.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean;
Configuring a Stripe RestClient in Spring
dependency-injection
http-client
configuration
Intermediate
7 steps
go
package parser import ( "fmt"
Parsing access logs with named regex groups in Go
regex
named-groups
parsing
Intermediate
5 steps
java
public class GitHubUserClient { private final HttpClient http = HttpClient.newBuilder() .connectTimeout(Duration.ofSeconds(10))
Calling the GitHub API with Java's HttpClient
http-client
json-deserialization
error-handling
Intermediate
9 steps
ruby
require "yaml" require "pathname" class AppConfig
A typed config loader in Ruby
yaml
configuration
recursion
Intermediate
8 steps
rust
use axum::{ async_trait, body::Bytes, extract::FromRequest,
A strict JSON extractor in Axum
extractors
traits
content-negotiation
Advanced
7 steps
go
package archive import ( "bytes"
Gzip round-trip compression in Go
compression
io
error-handling
Intermediate
5 steps
go
package handlers import ( "encoding/json"
Hardening JSON decoding in Go HTTP handlers
json
error-handling
http
Intermediate
8 steps
ruby
class OrdersController < ApplicationController rescue_from ActiveRecord::RecordNotUnique, with: :handle_duplicate_submission def create
Idempotent order creation in Rails
idempotency
database-constraints
error-handling
Intermediate
8 steps