Skip to content

Commit

Permalink
docs: update the sprig to sprout changes notes according to this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
42atomys committed May 9, 2024
1 parent 1676e31 commit b9f4baf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 74 deletions.
72 changes: 0 additions & 72 deletions NOTABLE_CHANGES_FROM_SPRIG_NOTES.md

This file was deleted.

82 changes: 82 additions & 0 deletions SPRIG_TO_SPROUT_CHANGES_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Migration Notes for Sprout Library
This document outlines the key differences and migration changes between the
Sprig and Sprout libraries. The changes are designed to enhance stability and
usability in the Sprout library.

This document will help contributors and maintainers understand the changes made
between the fork date and version 1.0.0 of the Sprout library.

It will be updated to reflect changes in future versions of the library.

This document will also assist in creating the migration guide when version 1.0 is ready.


## Error Handling Enhancements
### General Error Handling
In Sprig, errors within certain functions cause a panic.
In contrast, Sprout opts for returning nil or an empty value, improving safety
and predictability.

**Old Behavior (Sprig)**: Triggers a panic on error
```go
if err != nil {
panic("deepCopy error: " + err.Error())
}
```

**New Behavior (Sprout)**: Returns nil or an empty value on error
```go
if err != nil {
return nil, err
}
```

Methods that previously caused a panic in Sprig :
- DeepCopy
- MustDeepCopy
- ToRawJson
- Append
- Prepend
- Concat
- Chunk
- Uniq
- Compact
- Slice
- Without
- Rest
- Initial
- Reverse
- First
- Last
- Has
- Dig
- RandAlphaNumeric
- RandAlpha
- RandAscii
- RandNumeric
- RandBytes

## Function-Specific Changes

### MustDeepCopy

- **Sprig**: Accepts `nil` input, causing an internal panic.
- **Sprout**: Returns `nil` if input is `nil`, avoiding panic.

## Rand Functions

- **Sprig**: Causes an internal panic if the length parameter is zero.
- **Sprout**: Returns an empty string if the length is zero, ensuring stability.

## DateAgo

- **Sprig**: Does not support int32 and *time.Time; returns "0s".
- **Sprout**: Supports int32 and *time.Time and returns the correct duration.

## DateRound
- **Sprig**: Returns a corrected duration in positive form, even for negative inputs.
- **Sprout**: Accurately returns the duration, preserving the sign of the input.

## Base32Decode / Base64Decode
- **Sprig**: Decoding functions return the error string when the input is not a valid base64 encoded string.
- **Sprout**: Decoding functions return an empty string if the input is not a valid base64 encoded string, simplifying error handling.
4 changes: 2 additions & 2 deletions encoding_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (fh *FunctionHandler) Base64Encode(s string) string {
func (fh *FunctionHandler) Base64Decode(s string) string {
bytes, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return err.Error()
return ""
}
return string(bytes)
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func (fh *FunctionHandler) Base32Encode(s string) string {
func (fh *FunctionHandler) Base32Decode(s string) string {
bytes, err := base32.StdEncoding.DecodeString(s)
if err != nil {
return err.Error()
return ""
}
return string(bytes)
}
Expand Down

0 comments on commit b9f4baf

Please sign in to comment.