Better error handling and small wait before element queries (#55)

* Proper error handling and more logs

* Lint

* Add 1sec wait before looking for elements

* Clean up
This commit is contained in:
Pierre Jacquier
2023-04-03 07:26:32 -04:00
committed by GitHub
parent 24c0d1054c
commit 9f45958083
3 changed files with 1699 additions and 689 deletions

2362
.pnp.cjs generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { CadDiffPage } from '../components/diff/CadDiffPage' import { CadDiffPage } from '../components/diff/CadDiffPage'
import { Commit, DiffEntry, Message, MessageIds, Pull } from './types' import { Commit, DiffEntry, MessageIds, Pull } from './types'
import { import {
getGithubPullUrlParams, getGithubPullUrlParams,
mapInjectableDiffElements, mapInjectableDiffElements,
@ -21,6 +21,8 @@ async function injectDiff(
files: DiffEntry[], files: DiffEntry[],
document: Document document: Document
) { ) {
// TODO: find a better way, but this helps waiting for the full diff
await new Promise(resolve => setTimeout(resolve, 1000));
const map = mapInjectableDiffElements(document, files) const map = mapInjectableDiffElements(document, files)
const root = createReactRoot(document) const root = createReactRoot(document)
const cadDiffPage = React.createElement(CadDiffPage, { const cadDiffPage = React.createElement(CadDiffPage, {
@ -39,14 +41,18 @@ async function injectPullDiff(
pull: number, pull: number,
document: Document document: Document
) { ) {
const files = await chrome.runtime.sendMessage<Message, DiffEntry[]>({ const filesResponse = await chrome.runtime.sendMessage({
id: MessageIds.GetGithubPullFiles, id: MessageIds.GetGithubPullFiles,
data: { owner, repo, pull }, data: { owner, repo, pull },
}) })
const pullData = await chrome.runtime.sendMessage<Message, Pull>({ if ('error' in filesResponse) throw filesResponse.error
const files = filesResponse as DiffEntry[]
const pullDataResponse = await chrome.runtime.sendMessage({
id: MessageIds.GetGithubPull, id: MessageIds.GetGithubPull,
data: { owner, repo, pull }, data: { owner, repo, pull },
}) })
if ('error' in pullDataResponse) throw pullDataResponse.error
const pullData = pullDataResponse as Pull
const sha = pullData.head.sha const sha = pullData.head.sha
const parentSha = pullData.base.sha const parentSha = pullData.base.sha
await injectDiff(owner, repo, sha, parentSha, files, document) await injectDiff(owner, repo, sha, parentSha, files, document)
@ -58,10 +64,12 @@ async function injectCommitDiff(
sha: string, sha: string,
document: Document document: Document
) { ) {
const commit = await chrome.runtime.sendMessage<Message, Commit>({ const response = await chrome.runtime.sendMessage({
id: MessageIds.GetGithubCommit, id: MessageIds.GetGithubCommit,
data: { owner, repo, sha }, data: { owner, repo, sha },
}) })
if ('error' in response) throw response.error
const commit = response as Commit
if (!commit.files) throw Error('Found no file changes in commit') if (!commit.files) throw Error('Found no file changes in commit')
if (!commit.parents.length) throw Error('Found no commit parent') if (!commit.parents.length) throw Error('Found no commit parent')
const parentSha = commit.parents[0].sha const parentSha = commit.parents[0].sha

View File

@ -7564,7 +7564,7 @@ __metadata:
"fsevents@patch:fsevents@2.3.2#~builtin<compat/fsevents>, fsevents@patch:fsevents@^2.3.2#~builtin<compat/fsevents>, fsevents@patch:fsevents@~2.3.2#~builtin<compat/fsevents>": "fsevents@patch:fsevents@2.3.2#~builtin<compat/fsevents>, fsevents@patch:fsevents@^2.3.2#~builtin<compat/fsevents>, fsevents@patch:fsevents@~2.3.2#~builtin<compat/fsevents>":
version: 2.3.2 version: 2.3.2
resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=18f3a7" resolution: "fsevents@patch:fsevents@npm%3A2.3.2#~builtin<compat/fsevents>::version=2.3.2&hash=df0bf1"
dependencies: dependencies:
node-gyp: latest node-gyp: latest
conditions: os=darwin conditions: os=darwin
@ -12406,7 +12406,7 @@ __metadata:
"resolve@patch:resolve@^1.1.7#~builtin<compat/resolve>, resolve@patch:resolve@^1.14.2#~builtin<compat/resolve>, resolve@patch:resolve@^1.19.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.20.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.22.1#~builtin<compat/resolve>": "resolve@patch:resolve@^1.1.7#~builtin<compat/resolve>, resolve@patch:resolve@^1.14.2#~builtin<compat/resolve>, resolve@patch:resolve@^1.19.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.20.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.22.1#~builtin<compat/resolve>":
version: 1.22.1 version: 1.22.1
resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=07638b" resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=c3c19d"
dependencies: dependencies:
is-core-module: ^2.9.0 is-core-module: ^2.9.0
path-parse: ^1.0.7 path-parse: ^1.0.7
@ -12419,7 +12419,7 @@ __metadata:
"resolve@patch:resolve@^2.0.0-next.4#~builtin<compat/resolve>": "resolve@patch:resolve@^2.0.0-next.4#~builtin<compat/resolve>":
version: 2.0.0-next.4 version: 2.0.0-next.4
resolution: "resolve@patch:resolve@npm%3A2.0.0-next.4#~builtin<compat/resolve>::version=2.0.0-next.4&hash=07638b" resolution: "resolve@patch:resolve@npm%3A2.0.0-next.4#~builtin<compat/resolve>::version=2.0.0-next.4&hash=c3c19d"
dependencies: dependencies:
is-core-module: ^2.9.0 is-core-module: ^2.9.0
path-parse: ^1.0.7 path-parse: ^1.0.7
@ -13869,11 +13869,11 @@ __metadata:
"typescript@patch:typescript@^4.4.2#~builtin<compat/typescript>": "typescript@patch:typescript@^4.4.2#~builtin<compat/typescript>":
version: 4.9.5 version: 4.9.5
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=a1c5e5" resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=23ec76"
bin: bin:
tsc: bin/tsc tsc: bin/tsc
tsserver: bin/tsserver tsserver: bin/tsserver
checksum: 2eee5c37cad4390385db5db5a8e81470e42e8f1401b0358d7390095d6f681b410f2c4a0c496c6ff9ebd775423c7785cdace7bcdad76c7bee283df3d9718c0f20 checksum: ab417a2f398380c90a6cf5a5f74badd17866adf57f1165617d6a551f059c3ba0a3e4da0d147b3ac5681db9ac76a303c5876394b13b3de75fdd5b1eaa06181c9d
languageName: node languageName: node
linkType: hard linkType: hard