error-handling

java
package com.example.api.error;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.time.Instant;
import java.util.List;

Structured Error Responses with @RestControllerAdvice in Spring Boot

spring-boot rest-api exception-handling
by codesnips 3 tabs
typescript
export interface Todo {
  id: string;
  title: string;
  done: boolean;
}

Optimistic Todo Toggling in React with Rollback via useReducer

javascript typescript react
by codesnips 3 tabs
go
package store

import (
	"errors"
	"fmt"
	"time"

Wrapping Errors with Context and Inspecting Them via errors.Is and errors.As in Go

errors error-handling error-wrapping
by codesnips 3 tabs
typescript
import { z } from "zod";

export const rowSchema = z.object({
  email: z.string().email(),
  name: z.string().min(1, "name is required"),
  age: z.coerce.number().int().min(0, "age must be >= 0"),

Parse a CSV Upload into Typed Rows with Per-Row Validation Errors

typescript csv validation
by codesnips 3 tabs
rust
use std::collections::HashMap;
use serde_json::Value;

#[derive(Debug)]
pub enum DispatchError {
    UnknownCommand(String),

Compile-Time Command Dispatch Table With a Rust Declarative Macro

rust macros dispatch
by codesnips 3 tabs
javascript
'use strict';

const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const crypto = require('crypto');

Stream a Multipart Upload Through Gzip to Disk with stream.pipeline

nodejs streams backpressure
by codesnips 2 tabs
go
package validate

import (
	"regexp"
	"unicode/utf8"
)

Per-Field Signup Validation Errors With a Reusable Validator in Go

go validation http
by codesnips 2 tabs
python
import logging
from typing import Awaitable, Callable, List, Tuple

log = logging.getLogger("saga")

Compensation = Callable[[], Awaitable[None]]

Saga-Style Rollback With a Context-Managed Compensating Action Stack

saga rollback context-manager
by codesnips 3 tabs
rust
use serde::Deserialize;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
    pub server: ServerConfig,

Parsing a Layered TOML Config into Typed Sections with Serde and Defaults

rust serde toml
by codesnips 3 tabs
rust
use std::fs;
use std::num::ParseIntError;

fn read_port(path: &str) -> Result<u16, Box<dyn std::error::Error>> {
    let contents = fs::read_to_string(path)?;
    let port: u16 = contents.trim().parse()?;

Result and ? operator for clean error propagation

rust error-handling
by Marcus Chen 1 tab
rust
use serde::Deserialize;
use std::fmt;

#[derive(Debug, Deserialize)]
pub struct UserRecord {
    pub name: String,

Row-by-Row CSV Import Validation With Line-Numbered Errors in Rust

csv serde validation
by codesnips 3 tabs
rust
use std::collections::HashMap;
use std::sync::Mutex;

pub type AccountId = u64;
pub type Cents = i64;

Atomic Double-Entry Ledger Transfers With Rust Locking and Poison Recovery

ledger concurrency double-entry
by codesnips 3 tabs