refactor: improve an error handling (#35)
Description
- Improve error handling
- Get more details at logs
Related issue
Examples
API response:
{
"code": "INTERNAL_ERROR",
"message": "Internal server error.",
"detail": "RunnerError(cmd=\"sudo -n zfs list -po name,used,mountpoint,compressratio,available,type,origin,creation,dblab:datastateat -S dblab:datastateat -S creation -t filesystem -r dblab_pool\", inerr=\"exit status 1\", stderr=\"sudo: a password is required\n\" exit=\"1\")",
"hint": ""
}
Logs:
2020/01/08 18:02:56 [INFO] -> GET /status
2020/01/08 18:02:56 [DEBUG] Run(Local): "sudo -n zfs list -po name,used,mountpoint,compressratio,available,type,origin,creation,dblab:datastateat -S dblab:datastateat -S creation -t filesystem -r dblab_pool"
2020/01/08 18:02:56 [ERROR] GetDiskState: runner error: RunnerError(cmd="sudo -n zfs list -po name,used,mountpoint,compressratio,available,type,origin,creation,dblab:datastateat -S dblab:datastateat -S creation -t filesystem -r dblab_pool", inerr="exit status 1", stderr="sudo: a password is required
" exit="1")
2020/01/08 18:02:56 [ERROR] [INTERNAL_ERROR] - GET /status - RunnerError(cmd="sudo -n zfs list -po name,used,mountpoint,compressratio,available,type,origin,creation,dblab:datastateat -S dblab:datastateat -S creation -t filesystem -r dblab_pool", inerr="exit status 1", stderr="sudo: a password is required
" exit="1")
runner error
gitlab.com/postgres-ai/database-lab/pkg/services/provision.(*LocalRunner).Run
/home/akartasov/go/src/gitlab.com/postgres-ai/database-lab/pkg/services/provision/runners.go:122
gitlab.com/postgres-ai/database-lab/pkg/services/provision.ZfsListDetails
/home/akartasov/go/src/gitlab.com/postgres-ai/database-lab/pkg/services/provision/zfs.go:183
gitlab.com/postgres-ai/database-lab/pkg/services/provision.ZfsListFilesystems
/home/akartasov/go/src/gitlab.com/postgres-ai/database-lab/pkg/services/provision/zfs.go:165
gitlab.com/postgres-ai/database-lab/pkg/services/provision.(*provisionModeZfs).GetDiskState
/home/akartasov/go/src/gitlab.com/postgres-ai/database-lab/pkg/services/provision/mode_zfs.go:369
gitlab.com/postgres-ai/database-lab/pkg/services/cloning.(*baseCloning).GetInstanceState
/home/akartasov/go/src/gitlab.com/postgres-ai/database-lab/pkg/services/cloning/mode_base.go:294
gitlab.com/postgres-ai/database-lab/pkg/srv.(*Server).getInstanceStatus.func1
/home/akartasov/go/src/gitlab.com/postgres-ai/database-lab/pkg/srv/routes.go:17
gitlab.com/postgres-ai/database-lab/pkg/srv.(*Server).authorized.func1
/home/akartasov/go/src/gitlab.com/postgres-ai/database-lab/pkg/srv/middlewares.go:27
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2007
github.com/gorilla/mux.(*Router).ServeHTTP
/home/akartasov/go/pkg/mod/github.com/gorilla/mux@v1.7.3/mux.go:212
gitlab.com/postgres-ai/database-lab/pkg/srv.logging.func1
/home/akartasov/go/src/gitlab.com/postgres-ai/database-lab/pkg/srv/middlewares.go:15
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2007
net/http.serverHandler.ServeHTTP
/usr/local/go/src/net/http/server.go:2802
net/http.(*conn).serve
/usr/local/go/src/net/http/server.go:1890
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:1357
2020/01/08 18:02:56 http: superfluous response.WriteHeader call from gitlab.com/postgres-ai/database-lab/pkg/srv.writeJSON (util.go:48)
2020/01/08 18:02:56 [DEBUG] Response: {INTERNAL_ERROR Internal server error. RunnerError(cmd="sudo -n zfs list -po name,used,mountpoint,compressratio,available,type,origin,creation,dblab:datastateat -S dblab:datastateat -S creation -t filesystem -r dblab_pool", inerr="exit status 1", stderr="sudo: a password is required
" exit="1") }
2020/01/08 18:02:56 [DEBUG] Internal server error
Checklist
-
the MR description has been reviewed -
this MR contains text changes and they have been reviewed OR there are no texts changes -
this MR contains GUI/CLI changes and they have been reviewed OR there are no GUI/CLI changes -
this MR contains API changes and they have been reviewed OR there are no API changes
Edited by Anatoly Stansler