Parcourir la source

Adds better tracing of failed git commands

main
Eric Amodio il y a 6 ans
Parent
révision
e170e9ebd3
3 fichiers modifiés avec 17 ajouts et 9 suppressions
  1. +3
    -0
      CHANGELOG.md
  2. +10
    -5
      src/git/git.ts
  3. +4
    -4
      src/logger.ts

+ 3
- 0
CHANGELOG.md Voir le fichier

@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Adds better logging for failed git commands
### Changed
- Marks temporary files (used when showing comparisions with previous revisions) as read-only to help avoid accidental edits/saving

+ 10
- 5
src/git/git.ts Voir le fichier

@ -106,17 +106,22 @@ async function gitCommandCore(options: CommandOptions & { readonly correlationKe
}
let data: string;
let exception: Error | undefined;
try {
data = await promise;
}
catch (ex) {
exception = ex;
throw ex;
}
finally {
pendingCommands.delete(command);
const duration = process.hrtime(start);
const completedIn = `in ${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms`;
const completedIn = `${exception === undefined ? 'Completed' : 'FAILED'} in ${(duration[0] * 1000) + Math.floor(duration[1] / 1000000)} ms`;
Logger.log(`Completed${command} ${completedIn}`);
Logger.logGitCommand(`${gitCommand} ${completedIn}`, runOpts.cwd!);
Logger.log(`${exception === undefined ? 'Completed' : 'FAILED'}${command} ${completedIn}`);
Logger.logGitCommand(`${gitCommand} ${completedIn}`, runOpts.cwd!, exception);
}
if (encoding === 'utf8' || encoding === 'binary') return data;
@ -129,13 +134,13 @@ function gitCommandDefaultErrorHandler(ex: Error, options: CommandOptions, ...ar
if (msg) {
for (const warning of Objects.values(GitWarnings)) {
if (warning.test(msg)) {
Logger.warn('git', ...args, ` cwd='${options.cwd}'`, `\n ${msg.replace(/\r?\n|\r/g, ' ')}`);
Logger.warn('git', ...args, ` cwd='${options.cwd}'\n\n `, msg.replace(/\r?\n|\r/g, ' '));
return '';
}
}
}
Logger.error(ex, 'git', ...args, ` cwd='${options.cwd}'`, msg && `\n ${msg.replace(/\r?\n|\r/g, ' ')}`);
Logger.error(ex, 'git', ...args, ` cwd='${options.cwd}'\n\n `);
throw ex;
}

+ 4
- 4
src/logger.ts Voir le fichier

@ -53,11 +53,11 @@ export class Logger {
static error(ex: Error, classOrMethod?: string, ...params: any[]): void {
if (this.debug) {
console.error(this.timestamp, ConsolePrefix, classOrMethod, ex, ...params);
console.error(this.timestamp, ConsolePrefix, classOrMethod, ...params, ex);
}
if (this.output !== undefined && this.level !== OutputLevel.Silent) {
this.output.appendLine((this.debug ? [this.timestamp, classOrMethod, ex, ...params] : [classOrMethod, ex, ...params]).join(' '));
this.output.appendLine((this.debug ? [this.timestamp, classOrMethod, ...params, ex] : [classOrMethod, ...params, ex]).join(' '));
}
// Telemetry.trackException(ex);
@ -80,12 +80,12 @@ export class Logger {
static gitOutput: OutputChannel | undefined;
static logGitCommand(command: string, cwd: string): void {
static logGitCommand(command: string, cwd: string, ex?: Error): void {
if (this.level !== OutputLevel.Debug) return;
if (this.gitOutput === undefined) {
this.gitOutput = window.createOutputChannel(`${ExtensionOutputChannelName} (Git)`);
}
this.gitOutput.appendLine(`${this.timestamp} ${command} (${cwd})`);
this.gitOutput.appendLine(`${this.timestamp} ${command} (${cwd})${ex === undefined ? '' : `\n\n${ex.toString()}`}`);
}
}

Chargement…
Annuler
Enregistrer