star-micronics / react-native-star-io10

react-native-star-io10 is a library for supporting application development for Star Micronics devices.
Other
83 stars 54 forks source link

[BUG] Printing fails due to invalid commands structure #72

Closed ncpa0cpl closed 1 year ago

ncpa0cpl commented 1 year ago

Description

I've had a print fail in the middle of printing (half of the receipt was printed correctly). When investigating the issue I've determined that there was a invalid structure within the commands json file that is sent to the printer. Specifically there was an object with a category property with value of Printer and did not had the content property like other objects with that category. This was causing the printer to stop on that instruction and not continue the printing.

How it looked like:

{
  "category": "Printer",
  "contents": [
    {
      "category": "Printer"
    }
  ]
}

After manually changing the structure to this, that problem went away:

{
  "category": "Printer",
  "contents": [
    {
      "category": "Printer",
      "contents": []
    }
  ]
}

Your device where the bug occurs

Your printer

Your development environment

react-native-star-io10 pacakge at version 1.2.0

$: yarn react-native info

info Fetching system and libraries information...
System:
    OS: Linux 5.10 Manjaro Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
    Memory: 13.13 GB / 30.99 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.16.0 - /tmp/yarn--1659359595781-0.06555283617588592/node
    Yarn: 1.22.19 - /tmp/yarn--1659359595781-0.06555283617588592/yarn
    npm: 8.11.0 - /usr/local/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: AI-212.5712.43.2112.8609683
  Languages:
    Java: 11.0.16 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^17.0.2 => 17.0.2 
    react-native: 0.67.2 => 0.67.2 
  npmGlobalPackages:
    *react-native*: Not Found

To Reproduce

Steps to reproduce the behavior:

  1. Add an empty PrinterBuilder to the DocumentBuilder, and that document builder into StarXpandCommandBuilder
  2. Add any other builders with text print actions
  3. Get the commands json via the getCommands method
  4. Received json will have invalid structure
  5. Attempt to print
  6. Printer will stop printing once it gets to the invalid object

Example:

const printer = new PrinterBuilder()
      .add(new PrinterBuilder())
      .add(new PrinterBuilder().actionPrintText('Hello'));

    const commands = await new StarXpandCommandBuilder()
      .addDocument(new DocumentBuilder().addPrinter(printer))
      .getCommands();

Expected behavior

The structure of the commands should be valid, so that the printer never fails mid printing.

bandit-ibayashi commented 1 year ago

@ncpa0cpl Thank you for your report. We can reproduce this issue and will be fixed in the future update. We much appreciate your patience and understanding.

bandit-ibayashi commented 1 year ago

@ncpa0cpl We have fixed this Issue in the latest version. Thank you again for your report and patience!