Prevent accidentally shadowing these errors, which are used in defers, and
while at it, also fixed some linting warnings about unhandled errors, and
defers created in a loop.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -69,7 +69,7 @@ func (l *mockLoggingPlugin) StopLogging(file string) error {
|
| 69 | 69 |
return nil |
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 |
-func (l *mockLoggingPlugin) Capabilities() (cap Capability, err error) {
|
|
| 72 |
+func (l *mockLoggingPlugin) Capabilities() (Capability, error) {
|
|
| 73 | 73 |
return Capability{ReadLogs: true}, nil
|
| 74 | 74 |
} |
| 75 | 75 |
|
| ... | ... |
@@ -121,12 +121,12 @@ type GetTailReaderFunc func(ctx context.Context, f SizeReaderAt, nLogLines int) |
| 121 | 121 |
|
| 122 | 122 |
// NewLogFile creates new LogFile |
| 123 | 123 |
func NewLogFile(logPath string, capacity int64, maxFiles int, compress bool, decodeFunc MakeDecoderFn, perms os.FileMode, getTailReader GetTailReaderFunc) (*LogFile, error) {
|
| 124 |
- log, err := openFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, perms) |
|
| 124 |
+ logFile, err := openFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, perms) |
|
| 125 | 125 |
if err != nil {
|
| 126 | 126 |
return nil, err |
| 127 | 127 |
} |
| 128 | 128 |
|
| 129 |
- size, err := log.Seek(0, io.SeekEnd) |
|
| 129 |
+ size, err := logFile.Seek(0, io.SeekEnd) |
|
| 130 | 130 |
if err != nil {
|
| 131 | 131 |
return nil, err |
| 132 | 132 |
} |
| ... | ... |
@@ -141,7 +141,7 @@ func NewLogFile(logPath string, capacity int64, maxFiles int, compress bool, dec |
| 141 | 141 |
st <- logReadState{pos: pos}
|
| 142 | 142 |
|
| 143 | 143 |
return &LogFile{
|
| 144 |
- f: log, |
|
| 144 |
+ f: logFile, |
|
| 145 | 145 |
read: st, |
| 146 | 146 |
pos: pos, |
| 147 | 147 |
closed: make(chan struct{}),
|
| ... | ... |
@@ -43,14 +43,14 @@ func TestConcurrentLogging(t *testing.T) {
|
| 43 | 43 |
for ct := 0; ct < containers; ct++ {
|
| 44 | 44 |
ct := ct |
| 45 | 45 |
dir := t.TempDir() |
| 46 |
- g.Go(func() (err error) {
|
|
| 46 |
+ g.Go(func() (retErr error) {
|
|
| 47 | 47 |
logfile, err := NewLogFile(filepath.Join(dir, "log.log"), capacity, maxFiles, compress, createDecoder, 0o644, getTailReader) |
| 48 | 48 |
if err != nil {
|
| 49 | 49 |
return err |
| 50 | 50 |
} |
| 51 | 51 |
defer func() {
|
| 52 |
- if cErr := logfile.Close(); cErr != nil && err == nil {
|
|
| 53 |
- err = cErr |
|
| 52 |
+ if err := logfile.Close(); err != nil && retErr == nil {
|
|
| 53 |
+ retErr = err |
|
| 54 | 54 |
} |
| 55 | 55 |
}() |
| 56 | 56 |
lg, ctx := errgroup.WithContext(ctx) |
| ... | ... |
@@ -140,7 +140,7 @@ func (c *sharedTempFileConverter) openExisting(st stfcState, id stfID, v sharedT |
| 140 | 140 |
return res.fr, res.err |
| 141 | 141 |
} |
| 142 | 142 |
|
| 143 |
-func (c *sharedTempFileConverter) convert(f *os.File) (converted *os.File, size int64, err error) {
|
|
| 143 |
+func (c *sharedTempFileConverter) convert(f *os.File) (converted *os.File, size int64, _ error) {
|
|
| 144 | 144 |
dst, err := os.CreateTemp(c.TempDir, "dockerdtemp.*") |
| 145 | 145 |
if err != nil {
|
| 146 | 146 |
return nil, 0, err |
| ... | ... |
@@ -68,10 +68,10 @@ func makePluginClient(p plugingetter.CompatPlugin) (logPlugin, error) {
|
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 | 70 |
func makePluginCreator(name string, l logPlugin, scopePath func(s string) string) Creator {
|
| 71 |
- return func(logCtx Info) (logger Logger, err error) {
|
|
| 71 |
+ return func(logCtx Info) (logger Logger, retErr error) {
|
|
| 72 | 72 |
defer func() {
|
| 73 |
- if err != nil {
|
|
| 74 |
- pluginGetter.Get(name, extName, plugingetter.Release) |
|
| 73 |
+ if retErr != nil {
|
|
| 74 |
+ _, _ = pluginGetter.Get(name, extName, plugingetter.Release) |
|
| 75 | 75 |
} |
| 76 | 76 |
}() |
| 77 | 77 |
|
| ... | ... |
@@ -90,9 +90,9 @@ func makePluginCreator(name string, l logPlugin, scopePath func(s string) string |
| 90 | 90 |
logInfo: logCtx, |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 |
- cap, err := a.plugin.Capabilities() |
|
| 93 |
+ caps, err := a.plugin.Capabilities() |
|
| 94 | 94 |
if err == nil {
|
| 95 |
- a.capabilities = cap |
|
| 95 |
+ a.capabilities = caps |
|
| 96 | 96 |
} |
| 97 | 97 |
|
| 98 | 98 |
stream, err := openPluginStream(a) |
| ... | ... |
@@ -107,7 +107,7 @@ func makePluginCreator(name string, l logPlugin, scopePath func(s string) string |
| 107 | 107 |
return nil, errors.Wrapf(err, "error creating logger") |
| 108 | 108 |
} |
| 109 | 109 |
|
| 110 |
- if cap.ReadLogs {
|
|
| 110 |
+ if caps.ReadLogs {
|
|
| 111 | 111 |
return &pluginAdapterWithRead{a}, nil
|
| 112 | 112 |
} |
| 113 | 113 |
|
| ... | ... |
@@ -73,10 +73,9 @@ type logPluginProxyCapabilitiesResponse struct {
|
| 73 | 73 |
Err string |
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 |
-func (pp *logPluginProxy) Capabilities() (cap Capability, err error) {
|
|
| 76 |
+func (pp *logPluginProxy) Capabilities() (Capability, error) {
|
|
| 77 | 77 |
var ret logPluginProxyCapabilitiesResponse |
| 78 |
- |
|
| 79 |
- if err = pp.Call("LogDriver.Capabilities", nil, &ret); err != nil {
|
|
| 78 |
+ if err := pp.Call("LogDriver.Capabilities", nil, &ret); err != nil {
|
|
| 80 | 79 |
return Capability{}, err
|
| 81 | 80 |
} |
| 82 | 81 |
|
| ... | ... |
@@ -92,7 +91,7 @@ type logPluginProxyReadLogsRequest struct {
|
| 92 | 92 |
Config ReadConfig |
| 93 | 93 |
} |
| 94 | 94 |
|
| 95 |
-func (pp *logPluginProxy) ReadLogs(info Info, config ReadConfig) (stream io.ReadCloser, err error) {
|
|
| 95 |
+func (pp *logPluginProxy) ReadLogs(info Info, config ReadConfig) (stream io.ReadCloser, _ error) {
|
|
| 96 | 96 |
return pp.Stream("LogDriver.ReadLogs", logPluginProxyReadLogsRequest{
|
| 97 | 97 |
Info: info, |
| 98 | 98 |
Config: config, |