bafolts / tplant

Typescript to plantuml
https://segmentationfaults.com/tplant/default.html
GNU General Public License v3.0
266 stars 34 forks source link

Handle ECONNRESET on image file request. #78

Open NikitaIT opened 2 years ago

NikitaIT commented 2 years ago

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.

bafolts commented 2 years ago

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?

NikitaIT commented 2 years ago

@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