-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display megalinter errors to the user
- Loading branch information
Showing
18 changed files
with
249 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
Divider, | ||
SvgIcon, | ||
Theme, | ||
Typography, | ||
} from "@mui/material"; | ||
import { FC, useCallback, useEffect, useState } from "react"; | ||
import { MdErrorOutline } from "react-icons/md"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { makeStyles } from "tss-react/mui"; | ||
import { resetReport } from "../report/actions/error-report-action"; | ||
import { useReportStore } from "../report/stores/fe-report-store"; | ||
|
||
export const AnalysisErrorDialog: FC = () => { | ||
const { classes } = useStyles(); | ||
const { analysisError, reset } = useReportStore(); | ||
const [open, setOpen] = useState(!!analysisError); | ||
const navigate = useNavigate(); | ||
|
||
const handleClose = useCallback(() => { | ||
setOpen(false); | ||
resetReport(); | ||
navigate("/"); | ||
}, [navigate]); | ||
|
||
useEffect(() => { | ||
!!analysisError && setOpen(true); | ||
}, [analysisError]); | ||
|
||
return ( | ||
<Dialog | ||
maxWidth="lg" | ||
open={open} | ||
onAnimationEnd={reset} | ||
onClose={handleClose} | ||
> | ||
<DialogTitle sx={{ display: "flex", alignItems: "center", gap: 1 }}> | ||
<SvgIcon component={MdErrorOutline} color="error" /> | ||
An error has occured | ||
</DialogTitle> | ||
<Divider orientation="horizontal" /> | ||
<DialogContent className={classes.dialogContent}> | ||
<div> | ||
<Typography variant="body2" color="text.secondary"> | ||
Code | ||
</Typography> | ||
<Typography variant="body2" color="text.primary"> | ||
{analysisError?.errorCode} | ||
</Typography> | ||
</div> | ||
<div> | ||
<Typography variant="body2" color="text.secondary"> | ||
Message | ||
</Typography> | ||
<Typography variant="body2" color="text.primary"> | ||
{analysisError?.errorMessage} | ||
</Typography> | ||
</div> | ||
<div> | ||
<Typography variant="body2" color="text.secondary"> | ||
Details | ||
</Typography> | ||
<Typography variant="body2" color="text.primary"> | ||
{analysisError?.errorDetails} | ||
</Typography> | ||
</div> | ||
</DialogContent> | ||
<Divider orientation="horizontal" /> | ||
<DialogActions sx={{ padding: 2 }}> | ||
<Button variant="contained" onClick={handleClose}> | ||
Close | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
const useStyles = makeStyles()((theme: Theme) => ({ | ||
dialogContent: { | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: theme.spacing(2), | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ReportStore } from "../stores/fe-report-store"; | ||
|
||
export const resetReport = () => { | ||
const { unsubscribe, reset } = ReportStore.getState(); | ||
|
||
unsubscribe && unsubscribe(); | ||
reset(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 15 additions & 12 deletions
27
packages/app/src/report/actions/subscribe-report-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import { AnalysisStatus, ReportState } from "shared-types"; | ||
import { subscribe } from "../../ws-client"; | ||
import { ReportStore } from "../stores/fe-report-store"; | ||
import { subscribe } from "../utils/ws-client"; | ||
|
||
export const subscribeToLintProgress = (requestId: string) => { | ||
export const subscribeToReportProgress = (requestId: string) => { | ||
console.log("subscribing to WS..."); | ||
// clear previous error | ||
ReportStore.setState({ subscriptionError: undefined }); | ||
ReportStore.setState({ wsError: undefined }); | ||
|
||
const unsubscribe = subscribe( | ||
const unsubscribe = subscribe({ | ||
requestId, | ||
(msg: Partial<ReportState>) => { | ||
if (msg.status && msg.status === AnalysisStatus.Completed) { | ||
onMessage: (msg: Partial<ReportState>) => { | ||
const completed = msg.status && msg.status === AnalysisStatus.Completed; | ||
const error = !!msg.analysisError; | ||
if (completed || error) { | ||
// close ws connection on completed/error | ||
unsubscribe(); | ||
} | ||
ReportStore.setState({ ...msg }); | ||
}, | ||
() => { | ||
onError: () => { | ||
ReportStore.setState({ | ||
subscriptionError: "Web socket connection error", | ||
wsError: "Web socket connection error", | ||
}); | ||
}, | ||
() => { | ||
onClose: () => { | ||
const { inProgress } = ReportStore.getState(); | ||
inProgress && | ||
ReportStore.setState({ | ||
subscriptionError: "Web socket connection closed while scanning", | ||
wsError: "Web socket connection closed while scanning", | ||
}); | ||
} | ||
); | ||
}, | ||
}); | ||
ReportStore.setState({ unsubscribe }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/backend/src/megalinter/parsers/parse-errors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { MegalinterErrorMessage, MessageType } from "../megalinter-types"; | ||
import { parseMegalinterError } from "./parse-errors"; | ||
|
||
const storeMock = { | ||
set: jest.fn(), | ||
get: jest.fn().mockImplementation(() => ({ linters: [{ name: "devskim" }] })), | ||
subscribe: jest.fn(), | ||
}; | ||
|
||
describe("parse-errors", () => { | ||
test("parseMegalinterError", () => { | ||
const linterErrorMessage = { | ||
messageType: MessageType.ServerError, | ||
message: "Some error message", | ||
errorCode: "gitCloneError", | ||
errorDetails: { | ||
error: "Some error details", | ||
}, | ||
requestId: "123", | ||
}; | ||
parseMegalinterError( | ||
linterErrorMessage as MegalinterErrorMessage, | ||
storeMock | ||
); | ||
|
||
expect(storeMock.set).toBeCalledWith({ | ||
analysisError: { | ||
errorCode: "gitCloneError", | ||
errorMessage: "Some error message", | ||
errorDetails: "Some error details", | ||
}, | ||
}); | ||
}); | ||
|
||
test("parseMegalinterError should fail gracefully", () => { | ||
const linterErrorMessage = {}; | ||
|
||
try { | ||
parseMegalinterError( | ||
linterErrorMessage as MegalinterErrorMessage, | ||
storeMock | ||
); | ||
} catch (err) { | ||
expect(err.message).toBe("Unable to parse megalinter error message"); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ReportStore } from "../../stores/be-report-store"; | ||
import { logger } from "../../utils/logger"; | ||
import { MegalinterErrorMessage } from "../megalinter-types"; | ||
|
||
export const parseMegalinterError = ( | ||
msg: MegalinterErrorMessage, | ||
reportStore: ReportStore | ||
) => { | ||
try { | ||
const { errorCode, message, errorDetails } = msg; | ||
const analysisError = { | ||
errorCode, | ||
errorMessage: message, | ||
errorDetails: errorDetails.error, | ||
}; | ||
reportStore.set({ | ||
analysisError, | ||
}); | ||
} catch (err) { | ||
logger.megalinter.error(err); | ||
throw new Error("Unable to parse megalinter error message"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.