Skip to content

Proposal: Fix improper logging and error handling #635

@vg006

Description

@vg006

Overview

This is a proposal to update logger and fix error handling in general.

Origin

I have been using harbor CLI to manage my local registry for a while. So when I was trying to visit the audit logs of my registry using harbor logs, the process exited with a status code 1 without any proper logging or reason.

Image

Then after some time I found that the registry hasn't been started using harbor health (That's my bad), but though there isn't any proper response from the tool. So I just started to test other commands and their sub-commands, where I get varied response and logging.

Surprisingly upon executing harbor user elevate, The program just panicked.

Image

Also even the harbor user create just gets all the inputs and exits without proper logging, irrespective of the status of the registry.

Image

More Context

When I was working on this #634, the logger didn't log anything, as the logrus logger didn't set the output writer properly.
This may be a quick fix, but there are lot of lines of code performing logging, scattered across files.

Additionally, the logrus logger library which is being used in the project, has been in maintenance mode for nearly 6 years. (ref)

Due to these, the errors neither handled properly nor being logged. And at some places, errors are simply ignored, which isn't a good practice. (example).

Proposal

With all the above considerations in mind, I suggest to,

  1. Use the Charm's log library.

I suggest using the above lib, as the TUI is developed using Charm's components, styles and will be easy to set the theme across the CLI entirely

  1. Build a logger package using Cobra CLI's builtin stdout & stderr writter.
  2. Or use of any other logger such as Zerolog, Zap.

And for errors, I would highly suggest to define an internal errors package listing and mapping all the possible errors, that the tool may encounter. Like how it is implemented properly in the Harbor and its go-client SDK itself. (example)

So request the maintainers and the community to go through this proposal and share your thoughts and recommendations in this issue thread.

cc: @bupd @Vad1mo @OrlinVasilev @qcserestipy @NucleoFusion

Metadata

Metadata

Assignees

Labels

Priority: MediumAffecting a limited number of users,degrading the customer experience.enhancementNew feature or requestgoPull requests that update go code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions