# Code maintenance OP-15541 - Improve error messages and logs of  AMPF synchronization services/jobs

Project: OpenProject
Status: closed
URL: https://community.openproject.org/work_packages/OP-15541

## OPEN POINTS

_No work packages_

## Subtasks

| ID | Subject | Type | Status | Assignee | Project | Target versions |
| --- | --- | --- | --- | --- | --- | --- |
| OP-15406 | Improve logging and error handling on the Nextcloud Sync Service | Implementation | closed |  | OpenProject |  |
| OP-15405 | Improve logging and error handling on the One Drive Sync Service | Implementation | closed |  | OpenProject |  |

## Details

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable | Marcello Rocha Pereira |
| Designer |  |
| Developers | OP Dev Titan Team |
| Requires doc change | No |
| Date |  |
| Priority | Medium |
| Target versions | 14.4.0 |
| Sprint | 14.4.0 |
| Backlog bucket |  |
| Module |  |
| Accessibility | No |
| List |  |
| Labels |  |

## Estimates and progress

| Attribute | Value |
| --- | --- |
| Work |  |
| Remaining work |  |

## Description

## What?

This maintenance aims to bring long due improvements to logging, debugging and also end user error messages aimed at our users. The messages might end up differing slightly depending on the user being an instance admin or not.

## Why?

Right now we suffer from 3 main issues:

  - Error Messages aren't clear enough

  - Log contents don't offer a good idea of what is happening or why

  - Error Messages aren't localized

This makes debugging painful and doesn't help the end uses to figure out what is happening increasing support calls and making the feature seem sloppy/unstable.

## How?

### Treat the Errors coming from the StorageInteraction

Instead of returning a unclear message `Outbound request destination not found`, we should massage it a bit, given now the added context:

``` ruby
FileInfoQuery.call(auth_strategy:, storage:, file_id:) 
# On a 404 returns
ServiceResult.failure(result: :not_found, errors: StorageError.new(code: :not_found, data: { resonse: {} })
# When serialized we have
"not found | Outbound request destination was not found | #{response.to_json}"
```

Which is pretty close to what will be in the logs and shown to the user. On a given context (see above) we could change that message to

`The file #{file_link.origin_name} was not found on #{storage_name}` and have this localized.

### Increase logging capabilities

With the same structure as mentioned above, we have usually just the failure of the interaction, randomly on the logs. By using tagged logging we can add more context to the next calls so instead of `[SomeQuery] cryptic message sometimes` we can have `[FileListService][OneDrive::FilesQuery] not found | request params: #{} | response body: #{} | request_id: maybe some request id`

So an entire output (maybe on DEBUG level) could look like this.

``` text
[PrepareUploadService] Fetching upload link for #{storage.name} #{parent_id}
[PrepareUploadService] Using query Nextcloud::UploadFileQuery with upload_data: file_name:, folder_id:
[PrepareUploadService] [Nextcloud::UploadFileQuery] [OauthStragegy] Authenticated as User #{user remote}
[PrepareUploadService] [Nextcloud::UploadFileQuery] Requesting /nc/path/for/direct-uload with extra headers ... and payload ...
[PrepareUploadService] [Nextcloud::UploadFileQuery] Response received code: 432, response info
[PrepareUploadService] Failed with code: 432 | actual response sent to client
```
