otter icon indicating copy to clipboard operation
otter copied to clipboard

[Example issue] the behaviour is not as described.

Open tangwenqiang opened this issue 3 months ago • 1 comments

Here it will panic as the returned value is not 0 but 256. So the returned value is still from the loader instead of zero value when the loader returns error ?

	// Attempt to get the key with a loader function that returns an error
	value, err := cache.Get(ctx, key, otter.LoaderFunc[int, int](func(ctx context.Context, key int) (int, error) {
		time.Sleep(200 * time.Millisecond) // Simulate a slow operation
		// Return an error wrapped with otter.ErrNotFound
		return 256, fmt.Errorf("lalala: %w", otter.ErrNotFound)
	}))

	// Validate the returned value and error
	if value != 0 {
		panic("incorrect value") // Should return zero value on error
	}

tangwenqiang avatar Oct 04 '25 07:10 tangwenqiang

Hi, it seems I just forgot to fix the example when I was writing the code for this issue. Otter always returns exactly the data that the loader returns (if it's called at all).

maypok86 avatar Oct 04 '25 17:10 maypok86

The example has been fixed.

maypok86 avatar Nov 27 '25 21:11 maypok86