mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Remove string checking in API error handling
Use strongly typed errors to set HTTP status codes. Error interfaces are defined in the api/errors package and errors returned from controllers are checked against these interfaces. Errors can be wraeped in a pkg/errors.Causer, as long as somewhere in the line of causes one of the interfaces is implemented. The special error interfaces take precedence over Causer, meaning if both Causer and one of the new error interfaces are implemented, the Causer is not traversed. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
//
|
||||
// if it returns nil, the config channel will be active and return log
|
||||
// messages until it runs out or the context is canceled.
|
||||
func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *types.ContainerLogsOptions) (<-chan *backend.LogMessage, error) {
|
||||
func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *types.ContainerLogsOptions) (<-chan *backend.LogMessage, bool, error) {
|
||||
lg := logrus.WithFields(logrus.Fields{
|
||||
"module": "daemon",
|
||||
"method": "(*Daemon).ContainerLogs",
|
||||
@@ -30,24 +30,24 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
||||
})
|
||||
|
||||
if !(config.ShowStdout || config.ShowStderr) {
|
||||
return nil, errors.New("You must choose at least one stream")
|
||||
return nil, false, validationError{errors.New("You must choose at least one stream")}
|
||||
}
|
||||
container, err := daemon.GetContainer(containerName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if container.RemovalInProgress || container.Dead {
|
||||
return nil, errors.New("can not get logs from container which is dead or marked for removal")
|
||||
return nil, false, stateConflictError{errors.New("can not get logs from container which is dead or marked for removal")}
|
||||
}
|
||||
|
||||
if container.HostConfig.LogConfig.Type == "none" {
|
||||
return nil, logger.ErrReadLogsNotSupported
|
||||
return nil, false, logger.ErrReadLogsNotSupported{}
|
||||
}
|
||||
|
||||
cLog, cLogCreated, err := daemon.getLogger(container)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, false, err
|
||||
}
|
||||
if cLogCreated {
|
||||
defer func() {
|
||||
@@ -59,7 +59,7 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
||||
|
||||
logReader, ok := cLog.(logger.LogReader)
|
||||
if !ok {
|
||||
return nil, logger.ErrReadLogsNotSupported
|
||||
return nil, false, logger.ErrReadLogsNotSupported{}
|
||||
}
|
||||
|
||||
follow := config.Follow && !cLogCreated
|
||||
@@ -72,7 +72,7 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
||||
if config.Since != "" {
|
||||
s, n, err := timetypes.ParseTimestamps(config.Since, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, false, err
|
||||
}
|
||||
since = time.Unix(s, n)
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
||||
}
|
||||
}
|
||||
}()
|
||||
return messageChan, nil
|
||||
return messageChan, container.Config.Tty, nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) getLogger(container *container.Container) (l logger.Logger, created bool, err error) {
|
||||
|
||||
Reference in New Issue
Block a user