loreanvictor / tyfon

typed functions over network
https://loreanvictor.github.io/tyfon
MIT License
37 stars 4 forks source link

Log internal errors to console and do not show their message to clients #21

Open must opened 3 years ago

must commented 3 years ago

When running Tyfon watch, it runs the server as well but it will not display any console.log messages or errors coming from there.

loreanvictor commented 3 years ago

@must I could not reproduce this. Steps that I took:

  1. Create a fresh server and serve it
  2. Create a fresh client and install the server SDK
  3. Stop serving the server and instead run with watch:
    tyfon watch -c ../my-tyfon-client
  4. Modify contents of my-tyfon-server/index.ts:

    export interface User {
      name: string;
    }
    
    export const getMessage = async (user: User) => {
      console.log('Hola!');
      return `Hellow ${user.name}!`;
    };
  5. Invoke client code, so in my-tyfon-client, execute this:
    ts-node .

    As expected, I do get the log Hola! on the console on the server whenever I invoke the client.

must commented 3 years ago

I suppose this might only happen with actual errors. Can you try throwing an error on the backend?

loreanvictor commented 3 years ago

yes errors are not logged by default, they are instead passed to client. this is in sync with behavior in non server client contexts, i.e. when a function is called, the error is caught in the call site, and needs to be handled by the caller (for example, logged).

must commented 3 years ago

Yeah, that might make sense for some errors but not necessarily all and especially not in production.

loreanvictor commented 3 years ago

makes sense. a default logging mechanism would be pretty convenient, at least for internal server errors. I assume the standard behavior for these errors should actually change to "don't show error message to client, log it".