{"record":{"id":"946ec24314ad218d","repo":"duplicati/duplicati","slug":"failed-to-deserialize-delete-file-response","errorCode":null,"errorMessage":"Failed to deserialize delete file response","messagePattern":"Failed to deserialize delete file response","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Duplicati/Library/Backend/pCloud/pCloudBackend.cs","lineNumber":423,"sourceCode":"    /// <param name=\"cancellationToken\">CancellationToken that is combined with internal timeout token</param>\n    /// <returns></returns>\n    /// <exception cref=\"FileMissingException\">FileMissingException when file is not found</exception>\n    /// <exception cref=\"Exception\">Exceptions arising from either code execution or business logic when return code from pcloud indicates an error.</exception>\n    public async Task DeleteAsync(string remotename, CancellationToken cancellationToken)\n    {\n        using var request = CreateRequest($\"/deletefile?fileid={await GetFileId(remotename, cancellationToken).ConfigureAwait(false)}\", HttpMethod.Get);\n\n        using var response = await Utility.Utility.WithTimeout(_Timeouts.ShortTimeout, cancellationToken,\n            ct => _HttpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, ct)\n        ).ConfigureAwait(false);\n\n        response.EnsureSuccessStatusCode();\n\n        var content = await Utility.Utility.WithTimeout(_Timeouts.ShortTimeout, cancellationToken,\n            ct => response.Content.ReadAsStringAsync(ct)\n        ).ConfigureAwait(false);\n        var deleteFileResponse = JsonSerializer.Deserialize<pCloudDeleteResponse>(content)\n            ?? throw new Exception(\"Failed to deserialize delete file response\");\n\n        // If no error code is matched, result was == 0 so it successfully created the folder\n        if (deleteFileResponse.result == 2009)\n            throw new FileMissingException();\n\n        if (pCloudErrorList.ErrorMessages.TryGetValue(deleteFileResponse.result, out var message))\n            throw new Exception(message);\n\n        if (deleteFileResponse.result != 0)\n            throw new Exception(\n                Strings.pCloudBackend.FailedWithUnexpectedErrorCode(\"delete\", deleteFileResponse.result));\n    }\n\n    /// <summary>\n    /// Implementation of interface function to return hosnames used by the backend\n    /// </summary>\n    /// <param name=\"cancellationToken\">CancellationToken, in this call not used.</param>\n    /// <returns></returns>","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/duplicati/duplicati/blob/3f348be3e33f5d72d414e3ad55839c2ba34dda67/Duplicati/Library/Backend/pCloud/pCloudBackend.cs#L405-L441","documentation":"Thrown inside DeleteAsync when JsonSerializer.Deserialize<pCloudDeleteResponse>(content) returns null after a successful HTTP response. Same System.Text.Json null-token behavior as the other pCloud operations. Generic Exception indicating the delete response body was null/invalid despite a 2xx status.","triggerScenarios":"/deletefile returns HTTP success but the JSON body is the literal null token or maps to a null reference. Reached after EnsureSuccessStatusCode (line 417), so transport succeeded but the body is malformed.","commonSituations":"Transient server serialization issue; API response-shape change for delete; proxy returning an empty/null body; the file was deleted but the response envelope was non-standard.","solutions":["Log the raw response body to diagnose.","Verify the file is actually gone by listing the folder afterward (the delete may have succeeded).","Retry idempotently — DeleteAsync on an already-deleted file surfaces as result 2009 / FileMissingException.","Update pCloudDeleteResponse if the API envelope changed."],"exampleFix":"// before: null body is a hard error, file may already be deleted\nvar deleteFileResponse = JsonSerializer.Deserialize<pCloudDeleteResponse>(content)\n    ?? throw new Exception(\"Failed to deserialize delete file response\");\n\n// after: surface raw body for diagnosis\nvar deleteFileResponse = JsonSerializer.Deserialize<pCloudDeleteResponse>(content);\nif (deleteFileResponse is null)\n    throw new Exception($\"Failed to deserialize delete file response; raw: {content}\");","handlingStrategy":"retry","validationCode":"// Inspect the delete response body\nif (string.IsNullOrWhiteSpace(content) || content.Trim() == \"null\")\n    Console.Error.WriteLine(\"delete returned null body; verify file is gone\");","typeGuard":null,"tryCatchPattern":"try { await backend.DeleteAsync(remotename, ct); }\ncatch (Exception ex) when (ex.Message == \"Failed to deserialize delete file response\")\n{\n    // delete may have succeeded; list to confirm; retry idempotently if needed\n}","preventionTips":["Confirm the file is actually deleted (list the folder) before retrying.","Log the raw delete response body for diagnosis.","Keep pCloudDeleteResponse aligned with the API envelope."],"tags":["pcloud","delete","deserialization","json","api-response"],"backgroundTag":null,"analyzedSha":"3f348be3e33f5d72d414e3ad55839c2ba34dda67","analyzedAt":"2026-08-13T16:48:27.008Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}