cozy-labs/cozy-desktop

View on GitHub
core/remote/errors.js

Summary

Maintainability
F
3 days
Test Coverage

Function wrapError has 148 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const wrapError = (
  err /*: FetchError |  Error */,
  doc /*: ?SavedMetadata */
) /*: RemoteError */ => {
  if (isNetworkError(err)) {
Severity: Major
Found in core/remote/errors.js - About 5 hrs to fix

    Function wrapError has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

    const wrapError = (
      err /*: FetchError |  Error */,
      doc /*: ?SavedMetadata */
    ) /*: RemoteError */ => {
      if (isNetworkError(err)) {
    Severity: Minor
    Found in core/remote/errors.js - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File errors.js has 325 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     * @module core/remote/errors
     * @flow
     */
    
    
    Severity: Minor
    Found in core/remote/errors.js - About 3 hrs to fix

      Avoid too many return statements within this function.
      Open

                return new RemoteError({
                  code: INVALID_METADATA_CODE,
                  message: 'The local metadata for the document is corrupted',
                  err
                })
      Severity: Major
      Found in core/remote/errors.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                  return new RemoteError({
                    code: COZY_NOT_FOUND_CODE,
                    message: 'Remote Cozy could not be found',
                    err
                  })
        Severity: Major
        Found in core/remote/errors.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                    return new RemoteError({
                      code: PATH_TOO_DEEP_CODE,
                      message:
                        'The path of the document has too many levels for the remote Cozy',
                      err
          Severity: Major
          Found in core/remote/errors.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return new RemoteError({ err })
            Severity: Major
            Found in core/remote/errors.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return err
              Severity: Major
              Found in core/remote/errors.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                          return new RemoteError({
                            code: FILE_TOO_LARGE_CODE,
                            message: 'The file is larger than allowed by the remote Cozy',
                            err
                          })
                Severity: Major
                Found in core/remote/errors.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                            return new RemoteError({
                              code: NO_COZY_SPACE_CODE,
                              message: 'Not enough space available on remote Cozy',
                              err
                            })
                  Severity: Major
                  Found in core/remote/errors.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                              return new RemoteError({
                                code: INVALID_NAME_CODE,
                                message:
                                  'The name of the document contains characters forbidden by the remote Cozy',
                                err
                    Severity: Major
                    Found in core/remote/errors.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                return new RemoteError({
                                  code: MISSING_DOCUMENT_CODE,
                                  message: 'The updated document is missing on the remote Cozy',
                                  err
                                })
                      Severity: Major
                      Found in core/remote/errors.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                  return new RemoteError({
                                    code: UNKNOWN_REMOTE_ERROR_CODE,
                                    message:
                                      'The remote Cozy failed to process the request for an unknown reason',
                                    err
                        Severity: Major
                        Found in core/remote/errors.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                    return new RemoteError({
                                      code: UNREACHABLE_COZY_CODE,
                                      message: 'Cannot reach remote Cozy',
                                      err
                                    })
                          Severity: Major
                          Found in core/remote/errors.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                      return new RemoteError({
                                        code: UNKNOWN_INVALID_DATA_ERROR_CODE,
                                        message:
                                          'The data sent to the remote Cozy is invalid for some unhandled reason',
                                        err
                            Severity: Major
                            Found in core/remote/errors.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                        return new RemoteError({
                                          code: NEEDS_REMOTE_MERGE_CODE,
                                          message: 'The known remote document revision is outdated',
                                          err
                                        })
                              Severity: Major
                              Found in core/remote/errors.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                          return new RemoteError({
                                            code: INVALID_METADATA_CODE,
                                            message: 'The local metadata for the document is corrupted',
                                            err
                                          })
                                Severity: Major
                                Found in core/remote/errors.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                      return new RemoteError({
                                        code: MISSING_PARENT_CODE,
                                        message:
                                          'The parent directory of the document is missing on the remote Cozy',
                                        err
                                  Severity: Major
                                  Found in core/remote/errors.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                              return new RemoteError({
                                                code: INVALID_FOLDER_MOVE_CODE,
                                                message:
                                                  'The folder would be moved wihtin one of its sub-folders on the remote Cozy',
                                                err
                                    Severity: Major
                                    Found in core/remote/errors.js - About 30 mins to fix

                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                      Open

                                            case 413:
                                              if (isFileLargerThanAllowed(doc)) {
                                                return new RemoteError({
                                                  code: FILE_TOO_LARGE_CODE,
                                                  message: 'The file is larger than allowed by the remote Cozy',
                                      Severity: Major
                                      Found in core/remote/errors.js and 1 other location - About 1 hr to fix
                                      core/remote/errors.js on lines 229..242

                                      Duplicated Code

                                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                      Tuning

                                      This issue has a mass of 65.

                                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                      Refactorings

                                      Further Reading

                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                      Open

                                            case 404:
                                              if (hasNoReason(err)) {
                                                return new RemoteError({
                                                  code: COZY_NOT_FOUND_CODE,
                                                  message: 'Remote Cozy could not be found',
                                      Severity: Major
                                      Found in core/remote/errors.js and 1 other location - About 1 hr to fix
                                      core/remote/errors.js on lines 274..287

                                      Duplicated Code

                                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                      Tuning

                                      This issue has a mass of 65.

                                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                      Refactorings

                                      Further Reading

                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                      Open

                                        constructor({ cozyURL } /*: { cozyURL: string } */) {
                                          super('Cannot reach remote Cozy')
                                      
                                          if (Error.captureStackTrace) {
                                            Error.captureStackTrace(this, UnreachableError)
                                      Severity: Minor
                                      Found in core/remote/errors.js and 1 other location - About 55 mins to fix
                                      core/sync/errors.js on lines 36..45

                                      Duplicated Code

                                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                      Tuning

                                      This issue has a mass of 53.

                                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                      Refactorings

                                      Further Reading

                                      There are no issues that match your filters.

                                      Category
                                      Status