Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Error Handling & Return Varaibles #1998

Closed
arvindh123 opened this issue Nov 28, 2023 · 3 comments · Fixed by #2119
Closed

Refactoring Error Handling & Return Varaibles #1998

arvindh123 opened this issue Nov 28, 2023 · 3 comments · Fixed by #2119
Assignees
Milestone

Comments

@arvindh123
Copy link
Contributor

arvindh123 commented Nov 28, 2023

ENHANCEMENT

  1. Describe the enhancement you are requesting. Enhancements include:
    • code refactor

Description:

Suggestion 1:

In a substantial portion of the codebase, functions tend to return the outcome of a call directly, neglecting the handling of potential errors stemming from these calls.

Example:

func (svc Service) Function1(param1 string) (client, error) {
   return svc.anotherService.Call(param1)
}

Desired Solution:

Refactor these functions to incorporate error handling:

func (svc Service) Function1(param1 string) (client, error) {
   client, err := svc.anotherService.Call(param1)
   if err != nil {
      return client{}, errors.Wrap(svcerr.CallErr, err) 
   }
   return client, nil 
}

Suggestion 2:

Function with return struct/variable and error should return empty struct/variable on error return

Not looks function

func (svc service) ServiceCall(param1 string) (client, error) {
    cli, err := svc.anotherServiceCall(param1)

    if err != nil {
        return cli, errors.Wrap(svcerr.RepoCall, err)
    }

    return cli, nil
}

Looks good function

func (svc service) ServiceCall(param1 string) (client, error) {
    cli, err := svc.anotherServiceCall(param1)

    if err != nil {
        return client{}, errors.Wrap(svcerr.RepoCall, err)
    }

    return cli, nil
}
  1. Indicate the importance of this enhancement to you (must-have, should-have, nice-to-have).
    must-have
@arvindh123 arvindh123 changed the title Refactoring Error Handling Refactoring Error Handling & Return Varaibles Nov 28, 2023
@dborovcanin dborovcanin transferred this issue from another repository Jan 10, 2024
@dborovcanin dborovcanin added this to the S1 milestone Mar 20, 2024
@arvindh123 arvindh123 moved this from Backlog to In Progress in SuperMQ Mar 25, 2024
@arvindh123 arvindh123 moved this from In Progress to Todo in SuperMQ Mar 25, 2024
@WashingtonKK WashingtonKK moved this from Todo to In Progress in SuperMQ Mar 26, 2024
@WashingtonKK
Copy link
Contributor

This is addressed in this PR: https://github.com/absmach/magistrala/pull/2119

@WashingtonKK WashingtonKK linked a pull request Mar 26, 2024 that will close this issue
@WashingtonKK WashingtonKK moved this from In Progress to 🧪 Review and testing in progress in SuperMQ Apr 2, 2024
@dborovcanin dborovcanin moved this from 🧪 Review and testing in progress to In Progress in SuperMQ Apr 3, 2024
@dborovcanin dborovcanin modified the milestones: S1, S2 Apr 3, 2024
@dborovcanin
Copy link
Collaborator

dborovcanin commented Apr 9, 2024

This https://github.com/absmach/magistrala/pull/2088#discussion_r1557171749 should also be resolved in this issue.

@WashingtonKK
Copy link
Contributor

It is already being solved in this PR: https://github.com/absmach/magistrala/pull/2119

@WashingtonKK WashingtonKK moved this from In Progress to 🧪 Review and testing in progress in SuperMQ Apr 9, 2024
@dborovcanin dborovcanin modified the milestones: S2, S3 Apr 17, 2024
@dborovcanin dborovcanin removed this from the S3 milestone Apr 30, 2024
@dborovcanin dborovcanin modified the milestones: S4, S3 Apr 30, 2024
@arvindh123 arvindh123 modified the milestones: S3, S4 May 6, 2024
@github-project-automation github-project-automation bot moved this from 🧪 Review and testing in progress to Done in SuperMQ May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants