Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit34f8059

Browse files
committed
add sentry to extension
1 parentca07f5c commit34f8059

File tree

7 files changed

+87
-65
lines changed

7 files changed

+87
-65
lines changed

‎src/actions/setupActions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as git from '../services/git'
44
importloadWatchersfrom'./utils/loadWatchers'
55
importopenFilesfrom'./utils/openFiles'
66
importrunCommandsfrom'./utils/runCommands'
7+
importonErrorfrom'../services/sentry/onError'
78

89
constsetupActions=async(
910
workspaceRoot:vscode.WorkspaceFolder,
@@ -16,7 +17,7 @@ const setupActions = async (
1617
if(commits){
1718
for(constcommitofcommits){
1819
// TODO handle git errors
19-
awaitgit.loadCommit(commit)
20+
awaitgit.loadCommit(commit).catch(onError)
2021
}
2122
}
2223

@@ -27,7 +28,7 @@ const setupActions = async (
2728
loadWatchers(watchers||[],workspaceRoot.uri)
2829

2930
// 4. run command
30-
awaitrunCommands(commands||[],send)
31+
awaitrunCommands(commands||[],send).catch(onError)
3132
}
3233

3334
exportdefaultsetupActions

‎src/actions/solutionActions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import * as T from 'typings'
22
import*asvscodefrom'vscode'
33
import*asgitfrom'../services/git'
44
importsetupActionsfrom'./setupActions'
5+
importonErrorfrom'../services/sentry/onError'
56

67
constsolutionActions=async(
78
workspaceRoot:vscode.WorkspaceFolder,
89
stepActions:T.StepActions,
910
send:(action:T.Action)=>void,
1011
):Promise<void>=>{
1112
awaitgit.clear()
12-
returnsetupActions(workspaceRoot,stepActions,send)
13+
returnsetupActions(workspaceRoot,stepActions,send).catch(onError)
1314
}
1415

1516
exportdefaultsolutionActions

‎src/actions/tutorialConfig.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as vscode from 'vscode'
44
import{COMMANDS}from'../editor/commands'
55
importlanguageMapfrom'../editor/languageMap'
66
import*asgitfrom'../services/git'
7+
importonErrorfrom'services/sentry/onError'
78

89
interfaceTutorialConfigParams{
910
config:T.TutorialConfig
@@ -13,13 +14,14 @@ interface TutorialConfigParams {
1314

1415
consttutorialConfig=async(
1516
{ config, alreadyConfigured}:TutorialConfigParams,
16-
onError:(msg:T.ErrorMessage)=>void,
17+
handleError:(msg:T.ErrorMessage)=>void,
1718
)=>{
1819
if(!alreadyConfigured){
1920
// setup git, add remote
2021
awaitgit.initIfNotExists().catch(error=>{
22+
onError(newError('Git not found'))
2123
// failed to setup git
22-
onError({
24+
handleError({
2325
title:error.message,
2426
description:
2527
'Be sure you install Git. See the docs for help https://git-scm.com/book/en/v2/Getting-Started-Installing-Git',
@@ -28,7 +30,8 @@ const tutorialConfig = async (
2830

2931
// TODO if remote not already set
3032
awaitgit.setupRemote(config.repo.uri).catch(error=>{
31-
onError({title:error.message,description:'Remove your current Git project and restarting'})
33+
onError(error)
34+
handleError({title:error.message,description:'Remove your current Git project and restarting'})
3235
})
3336
}
3437

‎src/services/git/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
importnodefrom'../node'
22
importloggerfrom'../logger'
3+
importonErrorfrom'services/sentry/onError'
34

45
constgitOrigin='coderoad'
56

@@ -76,13 +77,18 @@ export async function version(): Promise<string | boolean> {
7677
return`${major}${minor}${patch}`
7778
}
7879
}
79-
thrownewError('Git not installed. Please install Git')
80+
constmessage='Git not installed. Please install Git'
81+
consterror=newError(message)
82+
onError(error)
83+
throwerror
8084
}
8185

8286
asyncfunctioninit():Promise<void>{
8387
const{ stderr}=awaitnode.exec('git init')
8488
if(stderr){
85-
thrownewError('Error initializing Git')
89+
consterror=newError('Error initializing Git')
90+
onError(error)
91+
throwerror
8692
}
8793
}
8894

‎src/services/node/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'fs'
33
import{join}from'path'
44
import{promisify}from'util'
55
import*asvscodefrom'vscode'
6+
importonErrorfrom'services/sentry/onError'
67

78
constasyncExec=promisify(cpExec)
89

@@ -12,7 +13,9 @@ class Node {
1213
// set workspace root for node executions
1314
constworkspaceRoots:vscode.WorkspaceFolder[]|undefined=vscode.workspace.workspaceFolders
1415
if(!workspaceRoots||!workspaceRoots.length){
15-
thrownewError('No workspace root path')
16+
consterror=newError('No workspace root path')
17+
onError(error)
18+
throwerror
1619
}
1720
constworkspaceRoot:vscode.WorkspaceFolder=workspaceRoots[0]
1821
this.workspaceRootPath=workspaceRoot.uri.path

‎src/services/testRunner/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import node from '../../services/node'
33
importloggerfrom'../../services/logger'
44
importparserfrom'./parser'
55
import{debounce,throttle}from'./throttle'
6+
importonErrorfrom'services/sentry/onError'
67

78
exportinterfacePayload{
89
stepId:string
@@ -76,6 +77,7 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
7677
}
7778
}else{
7879
// should never get here
80+
onError(newError(`Error with running test${JSON.stringify(payload)}`))
7981
callbacks.onError(payload)
8082
}
8183
}

‎src/webview/render.ts

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import{JSDOM}from'jsdom'
22
import*aspathfrom'path'
33
import*asvscodefrom'vscode'
4+
importonErrorfrom'services/sentry/onError'
45

56
constgetNonce=():string=>{
67
lettext=''
@@ -12,74 +13,79 @@ const getNonce = (): string => {
1213
}
1314

1415
asyncfunctionrender(panel:vscode.WebviewPanel,rootPath:string){
15-
// load copied index.html from web app build
16-
constdom=awaitJSDOM.fromFile(path.join(rootPath,'index.html'))
17-
const{ document}=dom.window
16+
try{
17+
// load copied index.html from web app build
18+
constdom=awaitJSDOM.fromFile(path.join(rootPath,'index.html'))
19+
const{ document}=dom.window
1820

19-
// set base href
20-
constbase:HTMLBaseElement=document.createElement('base')
21-
base.href=`vscode-resource:${rootPath}/`
21+
// set base href
22+
constbase:HTMLBaseElement=document.createElement('base')
23+
base.href=`vscode-resource:${rootPath}/`
2224

23-
document.head.appendChild(base)
25+
document.head.appendChild(base)
2426

25-
// used for CSP
26-
constnonces:string[]=[]
27+
// used for CSP
28+
constnonces:string[]=[]
2729

28-
// generate vscode-resource build path uri
29-
constcreateUri=(filePath:string):any=>{
30-
returnpanel.webview
31-
.asWebviewUri(vscode.Uri.file(filePath))
32-
.toString()
33-
.replace(/^\/+/g,'')// remove leading '/'
34-
.replace('/vscode-resource%3A',rootPath)// replace mangled resource path with root
35-
}
30+
// generate vscode-resource build path uri
31+
constcreateUri=(filePath:string):any=>{
32+
returnpanel.webview
33+
.asWebviewUri(vscode.Uri.file(filePath))
34+
.toString()
35+
.replace(/^\/+/g,'')// remove leading '/'
36+
.replace('/vscode-resource%3A',rootPath)// replace mangled resource path with root
37+
}
3638

37-
// fix paths for scripts
38-
constscripts:HTMLScriptElement[]=Array.from(document.getElementsByTagName('script'))
39-
for(constscriptofscripts){
40-
if(script.src){
41-
constnonce:string=getNonce()
42-
nonces.push(nonce)
43-
script.nonce=nonce
44-
script.src=createUri(script.src)
39+
// fix paths for scripts
40+
constscripts:HTMLScriptElement[]=Array.from(document.getElementsByTagName('script'))
41+
for(constscriptofscripts){
42+
if(script.src){
43+
constnonce:string=getNonce()
44+
nonces.push(nonce)
45+
script.nonce=nonce
46+
script.src=createUri(script.src)
47+
}
4548
}
46-
}
4749

48-
// add run-time script from webpack
49-
construnTimeScript=document.createElement('script')
50-
runTimeScript.nonce=getNonce()
51-
nonces.push(runTimeScript.nonce)
52-
constmanifest=awaitimport(path.join(rootPath,'asset-manifest.json'))
53-
runTimeScript.src=createUri(path.join(rootPath,manifest.files['runtime-main.js']))
54-
document.body.appendChild(runTimeScript)
50+
// add run-time script from webpack
51+
construnTimeScript=document.createElement('script')
52+
runTimeScript.nonce=getNonce()
53+
nonces.push(runTimeScript.nonce)
54+
constmanifest=awaitimport(path.join(rootPath,'asset-manifest.json'))
55+
runTimeScript.src=createUri(path.join(rootPath,manifest.files['runtime-main.js']))
56+
document.body.appendChild(runTimeScript)
5557

56-
// fix paths for links
57-
conststyles:HTMLLinkElement[]=Array.from(document.getElementsByTagName('link'))
58-
for(conststyleofstyles){
59-
if(style.href){
60-
style.href=createUri(style.href)
58+
// fix paths for links
59+
conststyles:HTMLLinkElement[]=Array.from(document.getElementsByTagName('link'))
60+
for(conststyleofstyles){
61+
if(style.href){
62+
style.href=createUri(style.href)
63+
}
6164
}
62-
}
6365

64-
// set CSP (content security policy) to grant permission to local files
65-
constcspMeta:HTMLMetaElement=document.createElement('meta')
66-
cspMeta.httpEquiv='Content-Security-Policy'
67-
cspMeta.content=
68-
[
69-
`default-src 'self'`,
70-
`connect-src https: http:`,
71-
`font-src${panel.webview.cspSource} http: https: data:`,
72-
`img-src${panel.webview.cspSource} https:`,
73-
`script-src${nonces.map(nonce=>`'nonce-${nonce}'`).join(' ')} data:`,
74-
`style-src${panel.webview.cspSource} https: 'self' 'unsafe-inline'`,
75-
].join('; ')+';'
76-
document.head.appendChild(cspMeta)
66+
// set CSP (content security policy) to grant permission to local files
67+
constcspMeta:HTMLMetaElement=document.createElement('meta')
68+
cspMeta.httpEquiv='Content-Security-Policy'
69+
cspMeta.content=
70+
[
71+
`default-src 'self'`,
72+
`connect-src https: http:`,
73+
`font-src${panel.webview.cspSource} http: https: data:`,
74+
`img-src${panel.webview.cspSource} https:`,
75+
`script-src${nonces.map(nonce=>`'nonce-${nonce}'`).join(' ')} data:`,
76+
`style-src${panel.webview.cspSource} https: 'self' 'unsafe-inline'`,
77+
].join('; ')+';'
78+
document.head.appendChild(cspMeta)
7779

78-
// stringify dom
79-
consthtml=dom.serialize()
80+
// stringify dom
81+
consthtml=dom.serialize()
8082

81-
// set view
82-
panel.webview.html=html
83+
// set view
84+
panel.webview.html=html
85+
}catch(error){
86+
onError(error)
87+
console.error(error)
88+
}
8389
}
8490

8591
exportdefaultrender

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp