Skip to content

Commit

Permalink
Improve error message when the main LOG action fails
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Oct 1, 2024
1 parent 31bfe9e commit 111e325
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions web/src/state/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ref, computed, shallowRef } from 'vue'
import default_git_actions from './default-git-actions.json'
import { parse } from '../utils/log-parser.js'
import { git, exchange_message, add_push_listener } from '../bridge.js'
import { git, exchange_message, add_push_listener, show_information_message } from '../bridge.js'
import { parse_config_actions } from '../views/GitInput.vue'

// ########################
Expand Down Expand Up @@ -67,17 +67,25 @@ export let git_run_log = async (/** @type {string} */ log_args) => {
log_args = log_args.replace(' --pretty={EXT_FORMAT}', ` --pretty=format:"${sep}%H${sep}%h${sep}%aN${sep}%aE${sep}%ad${sep}%D${sep}%s"`)
let stash_refs = await git('stash list --format="%h"')
log_args = log_args.replace('{STASH_REFS}', stash_refs.replaceAll('\n', ' '))
function log_error_handler(/** @type {Error} */ e) {
show_information_message('Git LOG failed. Did you change the command by hand? In the main view at the top left, click "Configure", then at the top right click "Reset", then "Save" and try again. If this didn\'t help, it might be a bug! Please open up a GitHub issue.')
throw e
}
// errors will be handled by GitInput
let [log_data, branch_data, stash_data, status_data, head_data] = await Promise.all([
git(log_args),
git(log_args).catch(log_error_handler),
git(`branch --list --all --format="%(upstream:remotename)${sep}%(refname)"`),
git('stash list --format="%h %gd"').catch(() => ''),
git('-c core.quotepath=false status'),
git('rev-parse --abbrev-ref HEAD'),
])
if (log_data == null)
return
let parsed = parse(log_data, branch_data, stash_data, sep, config.value['curve-radius'])
/** @type {ReturnType<parse>} */
let parsed = { commits: [], branches: [] }
try {
parsed = parse(log_data, branch_data, stash_data, sep, config.value['curve-radius'])
} catch (e) { log_error_handler(e) }
commits.value = parsed.commits
branches.value = parsed.branches
head_branch.value = head_data
Expand Down
2 changes: 1 addition & 1 deletion web/src/utils/log-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function parse(log_data, branch_data, stash_data, separator, curve_radius) {
/** @type {typeof graph_chars} */
let vis_chars = vis_str.trimEnd().split('')
if (vis_chars.some((v) => ! graph_chars.includes(v)))
throw new Error(`Could not parse output of GIT LOG (line:${row_no_s}). Did you change the command by hand? Please in the main view at the top left, click "Configure", then at the top right click "Reset", then "Save" and try again. If this didn't help, it might be a bug! Please open up a GitHub issue.`)
throw new Error(`Could not parse output of GIT LOG (line:${row_no_s})`)
// format %ad with --date=iso-local returns something like 2021-03-02 15:59:43 +0100
let datetime = iso_datetime?.slice(0, 19)
/**
Expand Down

0 comments on commit 111e325

Please sign in to comment.