Skip to content

Commit

Permalink
feat(log): added parseErrorsAndWarnings utility
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed Apr 10, 2023
1 parent 15774ec commit 7c1c1e2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PermissionsContext } from '../../../../context/permissionsContext'
import {
findExistingPermission,
findUpdatingPermission
} from '../../../../utils/helper'
} from '../../../../utils'

const useAddPermission = () => {
const {
Expand Down
3 changes: 3 additions & 0 deletions web/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './log'
export * from './types'
export * from './helper'
41 changes: 41 additions & 0 deletions web/src/utils/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const parseErrorsAndWarnings = (log: string) => {
const logLines = log.split('\n')
const errorLines: string[] = []
const warningLines: string[] = []

logLines.forEach((line: string, index: number) => {
// INFO: check if content in element starts with ERROR
if (/<.*>ERROR/gm.test(line)) {
const errorLine = line.substring(line.indexOf('E'), line.length - 1)
errorLines.push(errorLine)
}

// INFO: check if line starts with ERROR
else if (/^ERROR/gm.test(line)) {
errorLines.push(line)

logLines[index] =
`<font id="error_${errorLines.length - 1}">` +
logLines[index] +
'</font>'
}

// INFO: check if content in element starts with WARNING
else if (/<.*>WARNING/gm.test(line)) {
const warningLine = line.substring(line.indexOf('W'), line.length - 1)
warningLines.push(warningLine)
}

// INFO: check if line starts with WARNING
else if (/^WARNING/gm.test(line)) {
warningLines.push(line)

logLines[index] =
`<font id="warning_${warningLines.length - 1}">` +
logLines[index] +
'</font>'
}
})

return { errors: errorLines, warnings: warningLines, logLines }
}
6 changes: 6 additions & 0 deletions web/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ export interface TreeNode {
isFolder: boolean
children: Array<TreeNode>
}

export interface LogObject {
body: string
errors: string[]
warnings: string[]
}

0 comments on commit 7c1c1e2

Please sign in to comment.