Error Handling
Remy DI provides three different error handling strategies for retrieval functions. Choose the one that best fits your use case.
These functions return (T, error) and require explicit error handling:
Get[T]- Returns(T, error)GetAll[T]- Returns([]T, error)GetWithPairs[T]- Returns(T, error)GetWith[T]- Returns(T, error)
Use when: You need to handle errors explicitly and provide custom error handling logic.
| |
These functions return T and panic if an error occurs:
MustGet[T]- ReturnsT, panics on errorMustGetAll[T]- Returns[]T, panics on errorMustGetWithPairs[T]- ReturnsT, panics on errorMustGetWith[T]- ReturnsT, panics on error
Use when: You’re certain the element exists and failures should stop the application (e.g., during initialization).
| |
These functions return T or the zero value if an error occurs:
MaybeGet[T]- ReturnsTor zero valueMaybeGetAll[T]- Returns[]Tor empty sliceMaybeGetWithPairs[T]- ReturnsTor zero valueMaybeGetWith[T]- ReturnsTor zero value
Use when: The dependency is optional and you want to gracefully handle missing dependencies.
| |