MCPcopy
hub / github.com/syncthing/syncthing / wrap

Function wrap

internal/db/sqlite/db_update.go:99–123  ·  view source on GitHub ↗

wrap returns the error wrapped with the calling function name and optional extra context strings as prefix. A nil error wraps to nil.

(err error, context ...string)

Source from the content-addressed store, hash-verified

97// wrap returns the error wrapped with the calling function name and
98// optional extra context strings as prefix. A nil error wraps to nil.
99func wrap(err error, context ...string) error {
100 if err == nil {
101 return nil
102 }
103
104 prefix := "error"
105 pc, _, _, ok := runtime.Caller(1)
106 details := runtime.FuncForPC(pc)
107 if ok && details != nil {
108 prefix = strings.ToLower(details.Name())
109 if dotIdx := strings.LastIndex(prefix, "."); dotIdx > 0 {
110 prefix = prefix[dotIdx+1:]
111 }
112 }
113
114 if len(context) > 0 {
115 for i := range context {
116 context[i] = strings.TrimSpace(context[i])
117 }
118 extra := strings.Join(context, ", ")
119 return fmt.Errorf("%s (%s): %w", prefix, extra, err)
120 }
121
122 return fmt.Errorf("%s: %w", prefix, err)
123}

Callers 15

GetIndexIDMethod · 0.70
SetIndexIDMethod · 0.70
DropAllIndexIDsMethod · 0.70
GetDeviceSequenceMethod · 0.70
RemoteSequencesMethod · 0.70
GetDeviceFileMethod · 0.70
ListDevicesForFolderMethod · 0.70
DebugCountsMethod · 0.70
DropFolderMethod · 0.70
ListFoldersMethod · 0.70
cleanDroppedFoldersMethod · 0.70
startFolderDatabasesMethod · 0.70

Calls 1

NameMethod · 0.65

Tested by 1

TestErrorWrapFunction · 0.56