sessions icon indicating copy to clipboard operation
sessions copied to clipboard

About the error eater.

Open arlendotcn opened this issue 5 years ago • 2 comments

In real production, every error is important, but this project eats some errors:

func (s *session) Session() *sessions.Session {
	if s.session == nil {
		var err error
		s.session, err = s.store.Get(s.request, s.name)
		// error eater here
		if err != nil {
			log.Printf(errorFormat, err)
		}
	}
	return s.session
}

and it makes whole Session interface not reliable:

type Session interface {
	// Get returns the session value associated to the given key.
	Get(key interface{}) interface{}
	// Set sets the session value associated to the given key.
	Set(key interface{}, val interface{})
	// Delete removes the session value associated to the given key.
	Delete(key interface{})
	// Clear deletes all values in the session.
	Clear()
	// AddFlash adds a flash message to the session.
	// A single variadic argument is accepted, and it is optional: it defines the flash key.
	// If not defined "_flash" is used by default.
	AddFlash(value interface{}, vars ...string)
	// Flashes returns a slice of flash messages from the session.
	// A single variadic argument is accepted, and it is optional: it defines the flash key.
	// If not defined "_flash" is used by default.
	Flashes(vars ...string) []interface{}
	// Options sets confuguration for a session.
	Options(Options)
	// Save saves all sessions used during the current request.
	Save() error
}

so, in my project, i do need to rewrite it to get the error of memcached/redis server down, and make sure our users will not get any broken contents.

maybe golang's error is realy boring, but an error eater would be a serious problem too.

i'd forked and modified it to match my project's requirement: commit record

arlendotcn avatar Jul 16 '18 16:07 arlendotcn

You should create a pull-request. https://help.github.com/articles/creating-a-pull-request/

kelp404 avatar Aug 14 '18 02:08 kelp404

@kelp404 a pull-request created: https://github.com/gin-contrib/sessions/pull/69

arlendotcn avatar Aug 14 '18 06:08 arlendotcn