Skip to content

Commit

Permalink
remove .maybe() from Promise and Function prototype again
Browse files Browse the repository at this point in the history
experiment pretty much failed, this almost never adds any good

Side effect:

Fix search filter regex option
  • Loading branch information
phil294 committed Nov 29, 2024
1 parent 6756115 commit 0c356d2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ module.exports.activate = intercept_errors(function(/** @type {vscode.ExtensionC
: dev_server_url
let custom_css = vscode.workspace.getConfiguration(EXT_ID).get('custom-css')
if (custom_css)
custom_css = await postcss([postcss_sanitize({})]).process(custom_css, { from: undefined }).then((c) => c.css).maybe()
custom_css = await postcss([postcss_sanitize({})]).process(custom_css, { from: undefined }).then((c) => c.css).catch(() => 0)
let loading_prompt = is_production
? 'Loading (this should not take long)'
: 'Trying to connect to dev server... See CONTRIBUTING.md > "Building" for instructions'
Expand Down Expand Up @@ -336,7 +336,7 @@ module.exports.activate = intercept_errors(function(/** @type {vscode.ExtensionC
return hide_blame()

let blamed = await git.run(`blame -L${current_line + 1},${current_line + 1} --porcelain -- ${uri.fsPath}`, current_line_repo_index)
.then((b) => b.split('\n')).maybe()
.then((b) => b.split('\n')).catch(() => null)
if (! blamed)
return hide_blame()

Expand Down
13 changes: 0 additions & 13 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ String.prototype.hashCode = function() {
return hash
}

Function.prototype.maybe = function(/** @type {Array<any>} */ ..._) {
try {
// Can't use object spreading because this broke with JSON.stringify (??)
return this.apply(this, arguments)
} catch (error) {
return undefined
}
}

Promise.prototype.maybe = function() {
return this.catch(() => undefined)
}

/**
* To use in place of TypeScript's `!` operator
* @template T
Expand Down
2 changes: 1 addition & 1 deletion web/src/state/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export let main_view_action = async (/** @type {string} */ log_args) => {
throw error
}),
git('-c core.quotepath=false status'),
git('symbolic-ref HEAD', { ignore_errors: true }).maybe(),
git('symbolic-ref HEAD', { ignore_errors: true }).catch(() => null),
])
commits.value = parsed_log_data.commits
branches.value = parsed_log_data.branches
Expand Down
11 changes: 10 additions & 1 deletion web/src/views/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,18 @@ let txt_filter_regex = store.stateful_computed('filter-options-regex', false)
let txt_filter_ref = /** @type {Readonly<Vue.ShallowRef<HTMLInputElement|null>>} */ (useTemplateRef('txt_filter_ref')) // eslint-disable-line @stylistic/no-extra-parens
function txt_filter_filter(/** @type {Commit} */ commit) {
let search_for = txt_filter.value.toLowerCase()
/** @type {RegExp | undefined} */
let search_for_regex = undefined
if (txt_filter_regex.value)
try {
search_for_regex = new RegExp(search_for)
} catch (_) {
return false
}
for (let str of [commit.subject, commit.hash_long, commit.author_name, commit.author_email, ...commit.refs.map((r) => r.id)].map((s) => s.toLowerCase()))
if (txt_filter_regex.value) {
if (str?.match.maybe(search_for))
if (str?.match(search_for_regex || '?'))
return true
} else if (str?.includes(search_for))
return true
Expand Down
4 changes: 2 additions & 2 deletions web/src/vue-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function handle_error(/** @type {any[]} */ ...args) {
/* Proxied Vue render function. Accessing normal props results in more intermediate console errors, so this catches them and also provides the component name. This requires source maps to be disabled in production in order to work there. */
x.$?.type?.__name ||
/* standard props poking in the dark */
x.message || x.msg || x.data || x.body || x.stack || JSON.stringify.maybe(x, null, 4) || x.toString?.())?.toString?.() : '-')
x.message || x.msg || x.data || x.body || x.stack || (() => { try { return JSON.stringify(x, null, 4) } catch (_) { return 0 } })() || x.toString?.())?.toString?.() : '-')
.join('\n')
console_error(...args, new Error(), args[0]?.domChain ? `at element: ${JSON.stringify.maybe(args[0].domChain, null, 4)}` : '')
console_error(...args, new Error(), args[0]?.domChain ? ['at element', args[0].domChain] : '')
console.trace()
// debugger // eslint-disable-line no-debugger
show_error_message(prompt_error)
Expand Down

0 comments on commit 0c356d2

Please sign in to comment.