error-handling

rust
use serde::{Deserialize, Deserializer};
use time::OffsetDateTime;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserProfile {

Deserializing Optional and Renamed JSON API Fields with Serde in Rust

rust serde serde-json
by codesnips 2 tabs
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
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 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
go
package api

import (
	"encoding/json"
	"net/http"
)

Field-Level JSON Validation Errors in Go net/http Handlers

go net-http validation
by codesnips 3 tabs
typescript
import { z } from 'zod';

export const createUserSchema = z
  .object({
    email: z.string().email(),
    name: z.string().min(1).max(120),

Runtime validation for request bodies (Zod)

typescript validation api
by codesnips 3 tabs
rust
use std::fmt;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderState {
    Pending,
    Paid,

Type-State Order Lifecycle Machine With Compile-Time Transition Safety in Rust

state-machine enums type-state
by codesnips 3 tabs
ruby
# Basic exception handling
begin
  result = 10 / 0
rescue ZeroDivisionError => e
  puts "Error: #{e.message}"
  result = nil

Exception handling and error management

ruby exceptions error-handling
by Sarah Mitchell 3 tabs
typescript
import { z } from 'zod';

export const signupSchema = z
  .object({
    email: z.string().min(1, 'Email is required').email('Enter a valid email'),
    username: z

Field-Level Signup Validation with Zod and a Typed useZodForm Hook

react zod forms
by codesnips 3 tabs
rust
use std::time::Duration;
use rand::Rng;

#[derive(Clone, Debug)]
pub struct BackoffPolicy {
    pub base_delay: Duration,

Exponential Backoff With Jitter for Retrying Fallible Async Operations in Rust

rust tokio async
by codesnips 3 tabs
rust
use color_eyre::Result;

fn might_fail() -> Result<()> {
    Err(color_eyre::eyre::eyre!("Something went wrong"))
}

color-eyre for beautiful error reports with backtraces

rust error-handling cli
by Marcus Chen 1 tab