usdk icon indicating copy to clipboard operation
usdk copied to clipboard

[SDK] Better error logging, logdump

Open SaadBazaz opened this issue 1 year ago • 4 comments

Commands like usdk create can crash at any point. Currently, it's hard for developers to share logs as they have to copy-paste their entire chat.

Having a log file with "redacted" tokens might make it easiers for devs to share errors. Also, the content of the logfile can be directly uploaded to Telemetry like Sentry for error capture.

Possible approach

We can try-catch the CLI and then dump the stack trace + questionsSoFar into a .log file, stored in either the same folder as a file called .usdk-crash.dump maybe. Or, could be a JSON file. Really depends on international standards. See how npm manages it here (this should be a very helpful example, maybe we can just piggyback off of npm's or node's existing crash mechanisms).

I want more thoughts on this.

SaadBazaz avatar Nov 06 '24 11:11 SaadBazaz

Can this be done here? https://github.com/UpstreetAI/monorepo/blob/2fcdfa1d2a847d32c36c5ce700f8feb906eff43c/packages/usdk/cli.js#L2039

Pseudocode:

  try {
    await program.parseAsync();
  }
  catch(error) {
    // 1. log error in console
    console.error(error)

    // 2. show stack trace

    // 3. Write a log to file

    // 4. Display error, and path to log file
    console.info("USDK crashed. The error log is in ", pathToErrorFile)
  }

SaadBazaz avatar Nov 07 '24 08:11 SaadBazaz

Yes definitely a good addition, would help bridge crash/error context gap between devs and users

AbdurrehmanSubhani avatar Nov 07 '24 09:11 AbdurrehmanSubhani

Logs are already being written via winston.

Although it is not currently done, we could print the log location on a crash.

avaer avatar Nov 09 '24 02:11 avaer

Added a PR for better more reliable log dump to file and display log file path on crash: https://github.com/UpstreetAI/monorepo/pull/506

AbdurrehmanSubhani avatar Nov 11 '24 12:11 AbdurrehmanSubhani