pinojs / pino-abstract-transport

Write Pino transports easily
MIT License
34 stars 13 forks source link

ERR_UNHANDLED_ERROR #65

Open patilanz opened 1 year ago

patilanz commented 1 year ago

I'm working on Windows and I'm using it like this:

export const logger = pino({
  transport: {
    target:path.join(__dirname, 'pinoTransport.ts')
  }
});

// --- pinoTransports.ts ---
import build from 'pino-abstract-transport';
import {saveLog} from "./LogController";

export default function () {
  return build(function (source){
    source.on('data', obj => {
      console.log(obj);
      if(globalThis.is_prod)saveLog(obj);
    });
  }, {
    parseLine: line => {
      try {
        return JSON.parse(line);
      }catch(_){
        return {message: line};
      }
    }
  })
}

It was working perfectly until it didn't. The errors are not clear:

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({
  diagnosticCodes: [
    7022, 7006, 2695,
    7006, 7006, 7017,
    2695, 7006
  ]
})
    at new NodeError (node:internal/errors:363:5)
    at ThreadStream.emit (node:events:354:17)
    at destroy (D:\Programming\proyects\server\node_modules\thread-stream\index.js:349:12)
    at Worker.onWorkerMessage (D:\Programming\proyects\server\node_modules\thread-stream\index.js:164:7)
    at Worker.emit (node:events:365:28)
    at MessagePort.<anonymous> (node:internal/worker:241:53)
    at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:461:20)
    at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)
    at Worker.[kOnExit] (node:internal/worker:273:5)
    at Worker.<computed>.onexit (node:internal/worker:207:20) {
  code: 'ERR_UNHANDLED_ERROR',
  context: {
    diagnosticCodes: [
      7022, 7006, 2695,
      7006, 7006, 7017,
      2695, 7006
    ]
  }
}

pinojs github remarks this:

Running transports TypeScript code on TS-Node seems to be problematic on Windows systems, there's no official support for that yet.

If I change the file name to .js: pinoTransport.js it works, but before that it was also working on .ts

I'm using ts-node-dev this may be a problem. Any ideas?

mcollina commented 1 year ago

I don't know, it might well be a ts-node-dev issue!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.