exasol / extension-manager

Exasol extension-manager
MIT License
2 stars 0 forks source link

Export specfic errors to improve handling #176

Open pedroscaff opened 6 months ago

pedroscaff commented 6 months ago

Currently when we get a validation error from the EM we have to parse the error as following:

err = h.controller.UninstallExtension(ctx, customerDB, extensionID, extensionVersion)
if err != nil {
        emAPIError := emApiErrors.UnwrapAPIError(err)
        if emAPIError.Status == http.StatusBadRequest {
            return nil, exaerrors.NewBadRequestErrorF(err, "could not uninstall extension: %s", emAPIError.Message)
        }

        return nil, fmt.Errorf("Could not uninstall extension %w", err)
}

That limits us on the messages we can provide for the user and also our ability to maybe do our own internal error handling.

I propose we start exporting errors for specific issues that we can parse more easily, the end result would look like this:

err = h.controller.UninstallExtension(ctx, customerDB, extensionID, extensionVersion)
if err != nil {
        if err == emErrors.ErrUninstallExistingInstances {
            return nil, exaerrors.NewBadRequestErrorF(err, "could not uninstall extension because there are existing instances")
        }

        return nil, fmt.Errorf("Could not uninstall extension %w", err)
}

The errors would be declared in the extension manager, see example from the sql package: https://pkg.go.dev/database/sql#pkg-variables.