Repository: syncthing/syncthing
File: lib/model/model.go (Go)

Code before:
	}

	return ErrFolderNotRunning
}

// PendingDevices lists unknown devices that tried to connect.
func (m *model) PendingDevices() (map[protocol.DeviceID]db.ObservedDevice, error) {
	return m.db.PendingDevices()
}

// PendingFolders lists folders that we don't yet share with the offering devices.  It
// returns the entries grouped by folder and filters for a given device unless the
// argument is specified as EmptyDeviceID.
func (m *model) PendingFolders(device protocol.DeviceID) (map[string]db.PendingFolder, error) {
	return m.db.PendingFoldersForDevice(device)
}

// DismissPendingDevices removes the record of a specific pending device.
func (m *model) DismissPendingDevice(device protocol.DeviceID) error {
	l.Debugf("Discarding pending device %v", device)
	err := m.db.RemovePendingDevice(device)
	if err != nil {
		msg := "Failed to remove pending device entry"
		l.Warnf("%v: %v", msg, err)
		m.evLogger.Log(events.Failure, msg)
		return err
	}
	removedPendingDevices := []map[string]string{
		{"deviceID": device.String()},
	}
	m.evLogger.Log(events.PendingDevicesChanged, map[string]interface{}{
		"removed": removedPendingDevices,
	})
	return nil
}

// DismissPendingFolders removes records of pending folders.  Either a specific folder /
// device combination, or all matching a specific folder ID if the device argument is
// specified as EmptyDeviceID.
func (m *model) DismissPendingFolder(device protocol.DeviceID, folder string) error {
	var removedPendingFolders []map[string]string
	if device == protocol.EmptyDeviceID {
		l.Debugf("Discarding pending removed folder %s from all devices", folder)
		err := m.db.RemovePendingFolder(folder)
		if err != nil {
			msg := "Failed to remove pending folder entry"
			l.Warnf("%v: %v", msg, err)
			m.evLogger.Log(events.Failure, msg)
			return err
		}
		removedPendingFolders = []map[string]string{

Review comment (suggestion):
Usually the pattern is that either a function handles the error (logging, events, actions, ...) or returns it - not both. Some in other instances. If you want/need to add context to the error, you can wrap it before returning.

Code after:
	}

	return ErrFolderNotRunning
}

// PendingDevices lists unknown devices that tried to connect.
func (m *model) PendingDevices() (map[protocol.DeviceID]db.ObservedDevice, error) {
	return m.db.PendingDevices()
}

// PendingFolders lists folders that we don't yet share with the offering devices.  It
// returns the entries grouped by folder and filters for a given device unless the
// argument is specified as EmptyDeviceID.
func (m *model) PendingFolders(device protocol.DeviceID) (map[string]db.PendingFolder, error) {
	return m.db.PendingFoldersForDevice(device)
}

// DismissPendingDevices removes the record of a specific pending device.
func (m *model) DismissPendingDevice(device protocol.DeviceID) error {
	l.Debugf("Discarding pending device %v", device)
	err := m.db.RemovePendingDevice(device)
	if err != nil {
		return err
	}
	removedPendingDevices := []map[string]string{
		{"deviceID": device.String()},
	}
	m.evLogger.Log(events.PendingDevicesChanged, map[string]interface{}{
		"removed": removedPendingDevices,
	})
	return nil
}

// DismissPendingFolders removes records of pending folders.  Either a specific folder /
// device combination, or all matching a specific folder ID if the device argument is
// specified as EmptyDeviceID.
func (m *model) DismissPendingFolder(device protocol.DeviceID, folder string) error {
	var removedPendingFolders []map[string]string
	if device == protocol.EmptyDeviceID {
		l.Debugf("Discarding pending removed folder %s from all devices", folder)
		err := m.db.RemovePendingFolder(folder)
		if err != nil {
			return err
		}
		removedPendingFolders = []map[string]string{
			{"folderID": folder},
		}
	} else {
		l.Debugf("Discarding pending folder %s from device %v", folder, device)
		err := m.db.RemovePendingFolderForDevice(folder, device)
		if err != nil {