Skip to content

Commit

Permalink
fix: Log compiler errors in js config files
Browse files Browse the repository at this point in the history
Before this change javascript config files that had compilation errors or that threw their own errors wouldn't report the error, making debugging a mite more difficult than it should be: instead you'd get a useless "TypeError: Cannot read property 'errors' of undefined" message.  Now if the javascript config file tosses its cookies for whatever reason we can read what that reason was.
  • Loading branch information
kf6kjg committed Oct 13, 2020
1 parent 67a4d06 commit b6898d2
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/index.js
Expand Up @@ -126,19 +126,24 @@ module.exports = async function lintStaged(
printTaskOutput(ctx, logger)
return true
} catch (runAllError) {
const { ctx } = runAllError
if (ctx.errors.has(ApplyEmptyCommitError)) {
logger.warn(PREVENTED_EMPTY_COMMIT)
} else if (ctx.errors.has(GitError) && !ctx.errors.has(GetBackupStashError)) {
logger.error(GIT_ERROR)
if (ctx.shouldBackup) {
// No sense to show this if the backup stash itself is missing.
logger.error(RESTORE_STASH_EXAMPLE)
if ("ctx" in runAllError && runAllError.ctx && "errors" in runAllError.ctx && runAllError.ctx.errors) {
const { ctx } = runAllError
if (ctx.errors.has(ApplyEmptyCommitError)) {
logger.warn(PREVENTED_EMPTY_COMMIT)
} else if (ctx.errors.has(GitError) && !ctx.errors.has(GetBackupStashError)) {
logger.error(GIT_ERROR)
if (ctx.shouldBackup) {
// No sense to show this if the backup stash itself is missing.
logger.error(RESTORE_STASH_EXAMPLE)
}
}

printTaskOutput(ctx, logger)
return false
}

printTaskOutput(ctx, logger)
return false
// Probably a compilation error in the config js file. Pass it up to the outer error handler for logging.
throw runAllError
}
} catch (lintStagedError) {
if (lintStagedError === errConfigNotFound) {
Expand Down

0 comments on commit b6898d2

Please sign in to comment.