tplant icon indicating copy to clipboard operation
tplant copied to clipboard

Handle ECONNRESET on image file request.

Open NikitaIT opened this issue 2 years ago • 2 comments

I/O

In:

npx tplant --input ./**/*.ts --output ./Playground.svg

Out:

npx: installed 15 in 3.177s
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: socket hang up
    at connResetException (internal/errors.js:607:14)
    at Socket.socketOnEnd (_http_client.js:493:23)
    at Socket.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ClientRequest instance at:
    at Socket.socketOnEnd (_http_client.js:493:9)
    at Socket.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'ECONNRESET'
  

It is clear that this is not a mistake on your part. However, it would be nice to write something meaningful in addition to the log.

Proposed solution:

  1. Check URL maxlength and assert (414 Request-URI Too Large). https://github.com/bafolts/tplant/blob/f54c1def872ce9e4b12a38151ba3f63015fd8f88/src/index.ts#L145
  2. Handle ECONNRESET or add description about diagram size.

NikitaIT avatar Oct 26 '21 09:10 NikitaIT

When I run this command the Playground.svg file is generated without error. Adding additional error handling makes sense but not sure it will address the error seen here. Do you see the http request fail for requestImageFile?

bafolts avatar Oct 26 '21 23:10 bafolts

@bafolts I tried on a project with a puml of 8000 lines. Now I wrote a small example that can be run in the console.

script.js

#!/usr/bin/env node

const http = require('http');

const okLen = 10; // ok if <= 92
const errorLen = 93; // ECONNRESET if >= 93
const extension = 'svg';

http.get({
    host: 'www.plantuml.com',
    path: `/plantuml/${extension}/${encodeURI(input().repeat(errorLen))}`,
});

function input() {
    return `
    class LinkedListItem<T> {
        +item: T
        +next: LinkedListItem<T>
    }
    `;
}

Run:

node ./script.js

NikitaIT avatar Oct 29 '21 08:10 NikitaIT