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

Commit47ad9f8

Browse files
committed
update logging across app
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent0cce0af commit47ad9f8

File tree

19 files changed

+74
-75
lines changed

19 files changed

+74
-75
lines changed

‎src/actions/onRunReset.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Context from '../services/context/context'
44
importresetfrom'../services/reset'
55
import*ashooksfrom'../services/hooks'
66
importgetCommitHashByPositionfrom'../services/reset/lastHash'
7+
importloggerfrom'../services/logger'
78

89
typeResetAction={
910
type:'LATEST'|'POSITION'
@@ -22,7 +23,7 @@ const onRunReset = async (action: ResetAction, context: Context): Promise<void>
2223
constbranch=tutorial?.config.repo.branch
2324

2425
if(!branch){
25-
console.error('No repo branch found for tutorial')
26+
logger('Error:No repo branch found for tutorial')
2627
return
2728
}
2829

‎src/services/git/index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const stashAllFiles = async (): Promise<never | void> => {
99
// stash files including untracked (eg. newly created file)
1010
const{ stderr}=awaitexec({command:`git stash --include-untracked`})
1111
if(stderr){
12-
console.error(stderr)
12+
logger(`Error:${stderr}`)
1313
thrownewError('Error stashing files')
1414
}
1515
}
1616

1717
constcherryPickCommit=async(commit:string,count=0):Promise<never|void>=>{
1818
if(count>1){
19-
console.warn('cherry-pick failed')
19+
logger('cherry-pick failed')
2020
return
2121
}
2222
try{
@@ -26,8 +26,8 @@ const cherryPickCommit = async (commit: string, count = 0): Promise<never | void
2626
if(!stdout){
2727
thrownewError('No cherry-pick output')
2828
}
29-
}catch(error){
30-
console.log('cherry-pick-commit failed')
29+
}catch(error:any){
30+
logger(`cherry-pick-commit failed:${error.message}`)
3131
// stash all files if cherry-pick fails
3232
awaitstashAllFiles()
3333
returncherryPickCommit(commit,++count)
@@ -50,10 +50,10 @@ export function loadCommit(commit: string): Promise<never | void> {
5050
exportasyncfunctionsaveCommit(message:string):Promise<never|void>{
5151
const{ stdout, stderr}=awaitexec({command:`git commit -am '${message}'`})
5252
if(stderr){
53-
console.error(stderr)
53+
logger(`Error:${stderr}`)
5454
thrownewError('Error saving progress to Git')
5555
}
56-
logger(['save with commit & continuestdout',stdout])
56+
logger(stdout)
5757
}
5858

5959
exportasyncfunctionclear():Promise<Error|void>{
@@ -63,9 +63,9 @@ export async function clear(): Promise<Error | void> {
6363
if(!stderr){
6464
return
6565
}
66-
console.error(stderr)
67-
}catch(error){
68-
console.error(error)
66+
logger(`Error:${stderr}`)
67+
}catch(error:any){
68+
logger(`Error:${error.message}`)
6969
}
7070
thrownewError('Error cleaning up current unsaved work')
7171
}
@@ -127,7 +127,7 @@ export async function addRemote(repo: string): Promise<never | void> {
127127

128128
// validate the response is acceptable
129129
if(!alreadyExists&&!successfulNewBranch){
130-
console.error(stderr)
130+
logger(`Error:${stderr}`)
131131
thrownewError('Error adding git remote')
132132
}
133133
}
@@ -142,7 +142,8 @@ export async function checkRemoteExists(): Promise<boolean> {
142142
// string match on remote output
143143
// TODO improve the specificity of this regex
144144
return!!stdout.match(gitOrigin)
145-
}catch(error){
145+
}catch(error:any){
146+
logger(`Warn:${error.message}`)
146147
returnfalse
147148
}
148149
}
@@ -168,8 +169,9 @@ export async function loadCommitHistory(): Promise<string[]> {
168169
}
169170
// string match on remote output
170171
returnstdout.split('\n')
171-
}catch(error){
172+
}catch(error:any){
172173
// likely no git setup or no commits
174+
logger(`Warn:${error.message}`)
173175
return[]
174176
}
175177
}
@@ -189,8 +191,8 @@ export async function getCommitMessage(hash: string): Promise<string | null> {
189191
}
190192
// string match on remote output
191193
returnstdout
192-
}catch(error){
193-
logger('error',error)
194+
}catch(error:any){
195+
logger(`Error:${error.message}`)
194196
// likely no git commit message found
195197
returnnull
196198
}
@@ -204,8 +206,8 @@ export async function commitsExistsByMessage(message: string): Promise<boolean>
204206
returnfalse
205207
}
206208
return!!stdout.length
207-
}catch(error){
208-
logger('error',error)
209+
}catch(error:any){
210+
logger(`Error:${error.message}`)
209211
// likely no commit found
210212
returnfalse
211213
}

‎src/services/hooks/utils/openFiles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import{join}from'path'
22
import*asvscodefrom'vscode'
3+
importloggerfrom'../../logger'
34

45
constopenFiles=async(files:string[]=[]):Promise<void>=>{
56
if(!files.length){
@@ -16,7 +17,7 @@ const openFiles = async (files: string[] = []): Promise<void> => {
1617
constdoc=awaitvscode.workspace.openTextDocument(absoluteFilePath)
1718
awaitvscode.window.showTextDocument(doc,vscode.ViewColumn.One)
1819
}catch(error:any){
19-
console.log(`Failed to open file${filePath}:${error.message}`)
20+
logger(`Failed to open file${filePath}:${error.message}`)
2021
}
2122
}
2223
}

‎src/services/hooks/utils/runCommands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import{exec}from'../../node'
22
import{send}from'../../../commands'
3+
importloggerfrom'../../logger'
34

45
construnCommands=async(commands:string[]=[]):Promise<void>=>{
56
if(!commands.length){
@@ -14,9 +15,9 @@ const runCommands = async (commands: string[] = []): Promise<void> => {
1415
letresult:{stdout:string;stderr:string}
1516
try{
1617
result=awaitexec({ command})
17-
console.log(result)
18+
logger(result)
1819
}catch(error:any){
19-
console.error(`Command failed:${error.message}`)
20+
logger(`Command failed:${error.message}`)
2021
send({type:'COMMAND_FAIL',payload:{process:{ ...process,status:'FAIL'}}})
2122
return
2223
}

‎src/services/logger/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ export type Log = any
55
constlogChannel=getOutputChannel('CodeRoad (Logs)')
66

77
constlogger=(...messages:Log[]):void=>{
8-
// Inside vscode, you console.log does not allow more than 1 param
9-
// to get around it, we can log with multiple log statements
108
for(constmessageofmessages){
119
if(typeofmessage==='object'){
1210
logChannel.appendLine(message)

‎src/services/node/index.ts

Lines changed: 3 additions & 2 deletions
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{WORKSPACE_ROOT}from'../../environment'
6+
importloggerfrom'../logger'
67

78
constasyncExec=promisify(cpExec)
89
constasyncRemoveFile=promisify(fs.unlink)
@@ -35,13 +36,13 @@ export const removeFile = (...paths: string[]) => {
3536
exportconstreadFile=(...paths:string[]):Promise<string|void>=>{
3637
constfilePath=getWorkspacePath(...paths)
3738
returnasyncReadFile(getWorkspacePath(...paths),'utf8').catch((err)=>{
38-
console.warn(`Failed to read from${filePath}:${err.message}`)
39+
logger(`Failed to read from${filePath}:${err.message}`)
3940
})
4041
}
4142

4243
exportconstwriteFile=(data:any, ...paths:string[]):Promise<void>=>{
4344
constfilePath=getWorkspacePath(...paths)
4445
returnasyncWriteFile(filePath,data).catch((err)=>{
45-
console.warn(`Failed to write to${filePath}:${err.message}`)
46+
logger(`Failed to write to${filePath}:${err.message}`)
4647
})
4748
}

‎src/services/reset/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{exec,removeFile}from'../node'
2-
2+
importloggerfrom'../logger'
33
interfaceInput{
44
hash:string
55
branch:string
@@ -17,13 +17,13 @@ const reset = async ({ branch, hash }: Input): Promise<void> => {
1717
try{
1818
// if no git init, will initialize
1919
// otherwise re-initializes git
20-
awaitexec({command:'git init'}).catch(console.log)
20+
awaitexec({command:'git init'}).catch(logger)
2121

2222
// capture current branch
2323
consthasBranch=awaitexec({command:'git branch --show-current'})
2424
constlocalBranch=hasBranch.stdout
2525
// check if coderoad remote exists
26-
consthasRemote=awaitexec({command:'git remote -v'}).catch(console.warn)
26+
consthasRemote=awaitexec({command:'git remote -v'}).catch(logger)
2727
if(!hasRemote||!hasRemote.stdout||!hasRemote.stdout.length){
2828
thrownewError('No remote found')
2929
}elseif(!hasRemote.stdout.match(newRegExp(remote))){
@@ -64,8 +64,7 @@ const reset = async ({ branch, hash }: Input): Promise<void> => {
6464
command:`git reset --hard${hash}`,
6565
})
6666
}catch(error:any){
67-
console.error('Error resetting')
68-
console.error(error.message)
67+
logger(`Error resetting:${error.message}`)
6968
}
7069
}
7170

‎src/services/storage/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import*asvscodefrom'vscode'
22
import{readFile,writeFile}from'../node'
33
import{SESSION_STORAGE_PATH}from'../../environment'
4+
importloggerfrom'../logger'
45

56
// NOTE: localStorage is not available on client
67
// and must be stored in editor
@@ -46,17 +47,17 @@ class Storage<T> {
4647
returndata
4748
}
4849
}
49-
}catch(err){
50-
console.warn(`Failed to read or parse session file:${SESSION_STORAGE_PATH}/${this.filePath}.json`)
50+
}catch(err:any){
51+
logger(`Failed to read or parse session file:${SESSION_STORAGE_PATH}/${this.filePath}.json:${err.message}`)
5152
}
5253
}
5354
constvalue:string|undefined=awaitthis.storage.get(this.key)
5455
if(value){
5556
// 2. read from local storage
5657
try{
5758
returnJSON.parse(value)
58-
}catch(err){
59-
console.warn(`Failed to parse session state from local storage:${value}`)
59+
}catch(err:any){
60+
logger(`Failed to parse session state from local storage:${value}:${err.message}`)
6061
}
6162
}
6263
// 3. fallback to the default
@@ -83,7 +84,9 @@ class Storage<T> {
8384
try{
8485
writeFile(data,SESSION_STORAGE_PATH,`${this.filePath}.json`)
8586
}catch(err:any){
86-
console.warn(`Failed to write coderoad session to path:${SESSION_STORAGE_PATH}/${this.filePath}.json`)
87+
logger(
88+
`Failed to write coderoad session to path:${SESSION_STORAGE_PATH}/${this.filePath}.json:${err.message}`,
89+
)
8790
}
8891
}
8992
}

‎src/services/testRunner/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks): ((params: an
4040
// calculate level & step from position
4141
constlevel:TT.Level|null=data.levels.find((l)=>l.id===position.levelId)||null
4242
if(!level){
43-
console.warn(`Level "${position.levelId}" not found`)
43+
logger(`Error:Level "${position.levelId}" not found`)
4444
return
4545
}
4646
conststep:TT.Step|null=level.steps.find((s)=>s.id===position.stepId)||null
4747
if(!step){
48-
console.warn(`Step "${position.stepId}" not found`)
48+
logger(`Error:Step "${position.stepId}" not found`)
4949
return
5050
}
5151

‎src/services/webview/render.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as vscode from 'vscode'
33
import{asyncReadFile}from'../node'
44
import{onError}from'../telemetry'
55
import{CONTENT_SECURITY_POLICY_EXEMPTIONS}from'../../environment'
6+
importloggerfrom'../logger'
67

78
constgetNonce=():string=>{
89
lettext=''
@@ -142,8 +143,8 @@ async function render(panel: vscode.WebviewPanel, rootPath: string): Promise<voi
142143
// set view
143144
panel.webview.html=html
144145
}catch(error:any){
146+
logger(`Error:${error.message}`)
145147
onError(error)
146-
console.error(error)
147148
}
148149
}
149150

‎web-app/src/components/Error/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { css, jsx } from '@emotion/core'
55
importMarkdownfrom'../Markdown'
66
importButtonfrom'../../components/Button'
77
import{Theme}from'../../styles/theme'
8+
importloggerfrom'../../services/logger'
89

910
conststyles={
1011
container:(theme:Theme)=>({
@@ -42,7 +43,7 @@ const ErrorMarkdown = ({ error, send }: Props) => {
4243
React.useEffect(()=>{
4344
if(error){
4445
// log error
45-
console.log(`ERROR in markdown:${error.message}`)
46+
logger(`ERROR in markdown:${error.message}`)
4647
}
4748
},[error])
4849

‎web-app/src/components/ErrorBoundary/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class ErrorBoundary extends React.Component {
99
// Display fallback UI
1010
this.setState({errorMessage:error.message})
1111
// You can also log the error to an error reporting service
12-
logger('ERROR in component:',JSON.stringify(error))
13-
logger('ERROR info:',JSON.stringify(info))
12+
logger(`ERROR in component:${JSON.stringify(error)}`)
13+
logger(`ERROR info::${JSON.stringify(info)}`)
1414
}
1515

1616
publicrender(){

‎web-app/src/components/Markdown/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
importMarkdownItfrom'markdown-it'
22
importPrismfrom'prismjs'
3-
import{css,jsx,InterpolationWithTheme}from'@emotion/core'
3+
import{css,jsx}from'@emotion/core'
44
//@ts-ignore no types for package
55
importmarkdownEmojifrom'markdown-it-emoji'
66
import*asReactfrom'react'
77
// load prism styles & language support
88
import'./prism'
9+
importloggerfrom'../../services/logger'
910

1011
// markdown highlighter instance
1112
constmd:MarkdownIt=newMarkdownIt({
@@ -17,8 +18,8 @@ const md: MarkdownIt = new MarkdownIt({
1718

1819
try{
1920
hl=Prism.highlight(str,Prism.languages[lang],lang)
20-
}catch(error){
21-
console.error(error)
21+
}catch(error:any){
22+
logger(`Error highlighing markdown:${error.message}`)
2223
hl=md.utils.escapeHtml(str)
2324
}
2425

@@ -66,7 +67,7 @@ const Markdown = (props: Props) => {
6667
}catch(error){
6768
constmessage=`Failed to parse markdown for${props.children}`
6869
// TODO: onError(new Error(message))
69-
console.log(message)
70+
logger(message)
7071
html=`<div style='background-color: #FFB81A; padding: 0.5rem;'>
7172
<strong style='padding-bottom: 0.5rem;'>ERROR: Failed to parse markdown</strong>
7273
<p>${props.children}</p>

‎web-app/src/components/Router/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import*asReactfrom'react'
2+
importloggerfrom'../../services/logger'
23

34
interfaceRouterProps{
45
children:any
@@ -41,7 +42,7 @@ export const Router = ({ children, route }: RouterProps) => {
4142
}
4243
constmessage=`No Route matches for "${JSON.stringify(route)}"`
4344
// TODO: onError(new Error(message))
44-
console.warn(message)
45+
logger(message)
4546
returnnull
4647
}
4748

‎web-app/src/containers/SelectTutorial/LoadTutorialSummary.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Dialog } from '@alifd/next'
33
importuseFetchfrom'../../services/hooks/useFetch'
44
import*asTTfrom'typings/tutorial'
55
importLoadingPagefrom'../Loading'
6+
importloggerfrom'../../services/logger'
67

78
interfaceProps{
89
url:string
@@ -16,7 +17,7 @@ const LoadTutorialSummary = (props: Props) => {
1617
return<LoadingPagetext="Loading tutorial summary..."/>
1718
}
1819
if(error){
19-
console.log(`Failed to load tutorial summary:${error}`)
20+
logger(`Failed to load tutorial summary:${error}`)
2021
return<div>Error loading summary</div>
2122
}
2223
if(!data){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp