Skip to content

hackmd-cli export returns truncated document #34

@salim-b

Description

@salim-b

Problem

When I export this HackMD document using

hackmd-cli export --md 0HvXpVyxQku6LRXpT8Zz9Q > test.md

the resulting test.md file is "randomly" truncated.

Sometimes I get all lines, sometimes only n lines, sometimes even a broken file (I guess because the data stream returned is cut off in between valid UTF-8 character codes).

I only experienced this with one document so far and can't tell what exactly causes the issue. I tried to iteratively strip the file down to find out what lines exactly are triggering the issue, but I've capitulated after a short while. Due to the (perceived) "randomness" of the results, I suspect the problem is not the CLI itself but what it receives from the HackMD server (though I might be completely wrong about this of course).

Reproducible example

To make it as easy as possible for you to reproduce the issue, I created a simple bash script:

#!/bin/bash

# create an empty array to store the results
unset n_lines
declare -a n_lines

# export the document 20 times and each time print the number of lines
for i in {1..20} ; do
  n_lines+=(`hackmd-cli export --md 0HvXpVyxQku6LRXpT8Zz9Q | wc -l`)
  echo "In export number `printf "%02d" $i` the document had ${n_lines[-1]} lines."
done

# finally print a summary of these 20 exports (two columns)
printf "Summary:\n\n  times n_lines\n`echo "${n_lines[@]}" | tr ' ' '\n' | sort | uniq -c`\n"

The correct number of lines the script should report is 666 (the last newline char is not counted as a separate line by wc -l).

When I run the script on my system, I get results like:

In export number 01 the document had 666 lines.
In export number 02 the document had 575 lines.
In export number 03 the document had 485 lines.
In export number 04 the document had 666 lines.
In export number 05 the document had 666 lines.
In export number 06 the document had 666 lines.
In export number 07 the document had 666 lines.
In export number 08 the document had 666 lines.
In export number 09 the document had 666 lines.
In export number 10 the document had 666 lines.
In export number 11 the document had 655 lines.
In export number 12 the document had 575 lines.
In export number 13 the document had 655 lines.
In export number 14 the document had 666 lines.
In export number 15 the document had 666 lines.
In export number 16 the document had 575 lines.
In export number 17 the document had 485 lines.
In export number 18 the document had 666 lines.
In export number 19 the document had 575 lines.
In export number 20 the document had 575 lines.

Summary:

  times n_lines
      2 485
      5 575
      2 655
     11 666

Test file (Gist)

System details

  • OS: Ubuntu 20.04
  • hackmd-cli: @hackmd/hackmd-cli/1.1.1 linux-x64 node-v14.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions