Skip to content

bugs with enableDocumentMinification: true, with or without supported media file #71

@lauzonhomeschool

Description

@lauzonhomeschool

Describe the bug
enableDocumentMinification: true silently fails with no file output when .docx contains no media; when it does contain a media, it ends up with an untranslated version in the output file (after having held the minified translated version for a moment)

To Reproduce
Steps to reproduce the behavior:

  1. using 1.19.1
  2. sample call (almost verbatim from README.md), where inputPath and outputPath are valid full path strings:
  try {
    await deeplClient.translateDocument(inputPath, outputPath, 'en', 'fr', { enableDocumentMinification: true });
  } catch (error) {
    // If the error occurs after the document was already uploaded,
    // documentHandle will contain the document ID and key
    if (error.documentHandle) {
        const handle = error.documentHandle;
        console.log(`Document ID: ${handle.documentId}, ` + `Document key: ${handle.documentKey}`);
    } else {
        console.log(`Error occurred during document upload: ${error}`);
    }
  }
  1. use translateDocument on a .docx containing only text (no media)
  2. notice that output document is not generated and no error is shown, even with log.getLogger('deepl').setLevel('debug');
  3. notice that try/catch on deeplClient.translateDocument
  4. try the same, but put a break point on translator.js line 255: Image
  5. See that the error at that break point is similar to the following (and notice that the translated output file still temporarily exists with translated content at that point, although it doesn't at the end of the process):
    'Error: Error: no such file or directory, c:\\some_temp_path_here\\document_minification_5c6962c1-db3f-4b7a-bada-d25fb1ac5e82\\original_media
    at FsHelper.readdirSyncRecursive (C:\some_project_dir\\node_modules\\deepl-node\\dist\\fsHelper.js:37:19)
    at DocumentMinifier.replaceMediaInDir (C:\some_project_dir\\node_modules\\deepl-node\\dist\\documentMinifier.js:280:50)
    at DocumentMinifier.deminifyDocument (C:\some_project_dir\\node_modules\\deepl-node\\dist\\documentMinifier.js:175:14)
    at DeepLClient.translateDocument (C:\some_project_dir\\node_modules\\deepl-node\\dist\\translator.js:250:34)
  1. Notice that temp folder contains "minifiedDoc.docx" and "extracted_doc", but not "original_media"
  2. Put a break point at the first line of function deminifyDocument.
  3. Now try the same process with a .docx that contains an image.
  4. Notice that at the deminifyDocument breakpoint, output file contains a minified translated version as expected.
  5. Let the process run and notice that the output file contains a deminified version (i.e. image is back), but the text is no longer translated. (i.e. seems like it repackaged the wrong file)

Expected behavior

  1. The translated file is still generated correctly even if it contains no media, that way we can always use enableDocumentMinification: true with no prior knowledge of .docx content.
  2. When the code throws an unrecoverable error, it should bubble up to the caller, so it knows that the process failed.
  3. The deminified file should contain the translated version.

Desktop (please complete the following information):

  • OS: Windows 11
  • API version: 1.19.1
  • NodeJS version: 18.20.8

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions