From ed2d79a163c4d0d7520d58c776013cc01f1c76e7 Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:06:49 -0500 Subject: [PATCH 1/9] fix queryOptionButtons not restarting a search --- package-lock.json | 12 ++++++------ .../Sidebar/SidebarTabs/SearchTabPanel/index.tsx | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index db70105c..2fd061e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5135,9 +5135,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { @@ -9264,9 +9264,9 @@ } }, "node_modules/npm-run-all/node_modules/cross-spawn": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "version": "6.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.6.tgz", + "integrity": "sha512-VqCUuhcd1iB+dsv8gxPttb5iZh/D0iubSP21g36KXdEuf6I5JiioesUVjpCdHV9MZRUfVFlvwtIUyPfxo5trtw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx b/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx index 631878f1..182be797 100644 --- a/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx +++ b/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx @@ -1,5 +1,6 @@ import React, { useContext, + useRef, useState, } from "react"; @@ -44,8 +45,10 @@ const SearchTabPanel = () => { const {queryProgress, queryResults, startQuery, uiState} = useContext(StateContext); const [isAllExpanded, setIsAllExpanded] = useState(true); const [queryOptions, setQueryOptions] = useState([]); + const queryStringRef = useRef(""); const handleQueryInputChange = (ev: React.ChangeEvent) => { + queryStringRef.current = ev.target.value; const isCaseSensitive = queryOptions.includes(QUERY_OPTION.IS_CASE_SENSITIVE); const isRegex = queryOptions.includes(QUERY_OPTION.IS_REGEX); startQuery(ev.target.value, isRegex, isCaseSensitive); @@ -55,6 +58,11 @@ const SearchTabPanel = () => { newOptions: QUERY_OPTION[] ) => { setQueryOptions(newOptions); + if ("" !== queryStringRef.current) { + const isCaseSensitive = newOptions.includes(QUERY_OPTION.IS_CASE_SENSITIVE); + const isRegex = newOptions.includes(QUERY_OPTION.IS_REGEX); + startQuery(queryStringRef.current, isRegex, isCaseSensitive); + } }; return ( From 698dd28d360700bc351038863d421350b8fd3b0e Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:32:18 -0500 Subject: [PATCH 2/9] refactor according to code review --- .../SidebarTabs/SearchTabPanel/index.tsx | 51 ++++++++++++++----- src/contexts/StateContextProvider.tsx | 10 ++-- src/typings/worker.ts | 7 +++ 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx b/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx index 182be797..3468e83c 100644 --- a/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx +++ b/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx @@ -1,6 +1,5 @@ import React, { useContext, - useRef, useState, } from "react"; @@ -22,7 +21,10 @@ import { TAB_DISPLAY_NAMES, TAB_NAME, } from "../../../../../typings/tab"; -import {QUERY_PROGRESS_DONE} from "../../../../../typings/worker"; +import { + QUERY_PROGRESS_DONE, + QueryArgs, +} from "../../../../../typings/worker"; import {isDisabled} from "../../../../../utils/states"; import CustomTabPanel from "../CustomTabPanel"; import PanelTitleButton from "../PanelTitleButton"; @@ -36,6 +38,24 @@ enum QUERY_OPTION { IS_REGEX = "isRegex" } +/** + * Determines if the query is case-sensitive based on the provided query options. + * + * @param queryOptions + * @return True if the query is case-sensitive. + */ +const getIsCaseSensitive = + (queryOptions: QUERY_OPTION[]) => queryOptions.includes(QUERY_OPTION.IS_CASE_SENSITIVE); + +/** + * Determines if the query is a regular expression based on the provided query options. + * + * @param queryOptions + * @return True if the query is a regular expression. + */ +const getIsRegex = + (queryOptions: QUERY_OPTION[]) => queryOptions.includes(QUERY_OPTION.IS_REGEX); + /** * Displays a panel for submitting queries and viewing query results. * @@ -45,24 +65,31 @@ const SearchTabPanel = () => { const {queryProgress, queryResults, startQuery, uiState} = useContext(StateContext); const [isAllExpanded, setIsAllExpanded] = useState(true); const [queryOptions, setQueryOptions] = useState([]); - const queryStringRef = useRef(""); + const [queryString, setQueryString] = useState(""); + + const handleQuerySubmit = (newArgs: Partial) => { + startQuery({ + isCaseSensitive: getIsCaseSensitive(queryOptions), + isRegex: getIsRegex(queryOptions), + queryString: queryString, + ...newArgs, + }); + }; const handleQueryInputChange = (ev: React.ChangeEvent) => { - queryStringRef.current = ev.target.value; - const isCaseSensitive = queryOptions.includes(QUERY_OPTION.IS_CASE_SENSITIVE); - const isRegex = queryOptions.includes(QUERY_OPTION.IS_REGEX); - startQuery(ev.target.value, isRegex, isCaseSensitive); + setQueryString(ev.target.value); + handleQuerySubmit({queryString: ev.target.value}); }; + const handleQueryOptionsChange = ( _: React.MouseEvent, newOptions: QUERY_OPTION[] ) => { setQueryOptions(newOptions); - if ("" !== queryStringRef.current) { - const isCaseSensitive = newOptions.includes(QUERY_OPTION.IS_CASE_SENSITIVE); - const isRegex = newOptions.includes(QUERY_OPTION.IS_REGEX); - startQuery(queryStringRef.current, isRegex, isCaseSensitive); - } + handleQuerySubmit({ + isCaseSensitive: getIsCaseSensitive(newOptions), + isRegex: getIsRegex(newOptions), + }); }; return ( diff --git a/src/contexts/StateContextProvider.tsx b/src/contexts/StateContextProvider.tsx index 09d5eda3..8d215fec 100644 --- a/src/contexts/StateContextProvider.tsx +++ b/src/contexts/StateContextProvider.tsx @@ -26,6 +26,7 @@ import { FileSrcType, MainWorkerRespMessage, QUERY_PROGRESS_INIT, + QueryArgs, QueryResults, WORKER_REQ_CODE, WORKER_RESP_CODE, @@ -71,7 +72,7 @@ interface StateContextType { loadFile: (fileSrc: FileSrcType, cursor: CursorType) => void, loadPageByAction: (navAction: NavigationAction) => void, setLogLevelFilter: (newLogLevelFilter: LogLevelFilter) => void, - startQuery: (queryString: string, isRegex: boolean, isCaseSensitive: boolean) => void, + startQuery: (queryArgs: QueryArgs) => void, } const StateContext = createContext({} as StateContextType); @@ -333,11 +334,8 @@ const StateContextProvider = ({children}: StateContextProviderProps) => { } }, [postPopUp]); - const startQuery = useCallback(( - queryString: string, - isRegex: boolean, - isCaseSensitive: boolean - ) => { + const startQuery = useCallback((queryArgs: QueryArgs) => { + const {queryString, isRegex, isCaseSensitive} = queryArgs; setQueryResults(STATE_DEFAULT.queryResults); if (null === mainWorkerRef.current) { console.error("Unexpected null mainWorkerRef.current"); diff --git a/src/typings/worker.ts b/src/typings/worker.ts index 334f1cb0..233f397c 100644 --- a/src/typings/worker.ts +++ b/src/typings/worker.ts @@ -105,6 +105,12 @@ type WorkerReqMap = { }, }; +interface QueryArgs { + queryString: string; + isCaseSensitive: boolean; + isRegex: boolean; +} + type TextRange = [number, number]; interface QueryResultsType { @@ -190,6 +196,7 @@ export type { FileSrcType, MainWorkerReqMessage, MainWorkerRespMessage, + QueryArgs, QueryResults, QueryResultsType, WorkerReq, From 31d9609204dbb26511ad406ec74c1c60eaad83f1 Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:20:08 -0500 Subject: [PATCH 3/9] Update src/contexts/StateContextProvider.tsx Co-authored-by: Junhao Liao --- src/contexts/StateContextProvider.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/contexts/StateContextProvider.tsx b/src/contexts/StateContextProvider.tsx index cb6f6851..d26e0ad0 100644 --- a/src/contexts/StateContextProvider.tsx +++ b/src/contexts/StateContextProvider.tsx @@ -362,8 +362,11 @@ const StateContextProvider = ({children}: StateContextProviderProps) => { } }, [postPopUp]); - const startQuery = useCallback((queryArgs: QueryArgs) => { - const {queryString, isRegex, isCaseSensitive} = queryArgs; + const startQuery = useCallback(({ + isCaseSensitive, + isRegex, + queryString, + }: QueryArgs) => { setQueryResults(STATE_DEFAULT.queryResults); if (null === mainWorkerRef.current) { console.error("Unexpected null mainWorkerRef.current"); From 1bad3ccc88a9a9a8ee3999db888c9d0bcfb3d8c0 Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:10:19 -0500 Subject: [PATCH 4/9] refactor query related to `src/typings/query.ts`, change startQuery into object parameter signatures --- .../SidebarTabs/SearchTabPanel/index.tsx | 10 +++---- src/contexts/StateContextProvider.tsx | 24 ++++++---------- src/services/LogFileManager/index.ts | 14 ++++++---- src/services/MainWorker.ts | 15 ++-------- src/typings/query.ts | 28 +++++++++++++++++++ src/typings/worker.ts | 25 +---------------- 6 files changed, 54 insertions(+), 62 deletions(-) create mode 100644 src/typings/query.ts diff --git a/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx b/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx index 3468e83c..c32b5b2b 100644 --- a/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx +++ b/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx @@ -16,15 +16,15 @@ import UnfoldLessIcon from "@mui/icons-material/UnfoldLess"; import UnfoldMoreIcon from "@mui/icons-material/UnfoldMore"; import {StateContext} from "../../../../../contexts/StateContextProvider"; +import { + QUERY_PROGRESS_VALUE_MAX, + QueryArgs, +} from "../../../../../typings/query"; import {UI_ELEMENT} from "../../../../../typings/states"; import { TAB_DISPLAY_NAMES, TAB_NAME, } from "../../../../../typings/tab"; -import { - QUERY_PROGRESS_DONE, - QueryArgs, -} from "../../../../../typings/worker"; import {isDisabled} from "../../../../../utils/states"; import CustomTabPanel from "../CustomTabPanel"; import PanelTitleButton from "../PanelTitleButton"; @@ -144,7 +144,7 @@ const SearchTabPanel = () => { determinate={true} thickness={4} value={queryProgress * 100} - color={QUERY_PROGRESS_DONE === queryProgress ? + color={QUERY_PROGRESS_VALUE_MAX === queryProgress ? "success" : "primary"}/> diff --git a/src/contexts/StateContextProvider.tsx b/src/contexts/StateContextProvider.tsx index d26e0ad0..659f243b 100644 --- a/src/contexts/StateContextProvider.tsx +++ b/src/contexts/StateContextProvider.tsx @@ -24,6 +24,11 @@ import { DEFAULT_AUTO_DISMISS_TIMEOUT_MILLIS, LONG_AUTO_DISMISS_TIMEOUT_MILLIS, } from "../typings/notifications"; +import { + QUERY_PROGRESS_VALUE_MIN, + QueryArgs, + QueryResults, +} from "../typings/query"; import {UI_STATE} from "../typings/states"; import {SEARCH_PARAM_NAMES} from "../typings/url"; import { @@ -33,9 +38,6 @@ import { EVENT_POSITION_ON_PAGE, FileSrcType, MainWorkerRespMessage, - QUERY_PROGRESS_INIT, - QueryArgs, - QueryResults, WORKER_REQ_CODE, WORKER_RESP_CODE, WorkerReq, @@ -99,7 +101,7 @@ const STATE_DEFAULT: Readonly = Object.freeze({ numPages: 0, onDiskFileSizeInBytes: 0, pageNum: 0, - queryProgress: QUERY_PROGRESS_INIT, + queryProgress: QUERY_PROGRESS_VALUE_MIN, queryResults: new Map(), uiState: UI_STATE.UNOPENED, @@ -340,7 +342,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => { } case WORKER_RESP_CODE.QUERY_RESULT: setQueryProgress(args.progress); - if (QUERY_PROGRESS_INIT === args.progress) { + if (QUERY_PROGRESS_VALUE_MIN === args.progress) { setQueryResults(STATE_DEFAULT.queryResults); } else { setQueryResults((v) => { @@ -362,22 +364,14 @@ const StateContextProvider = ({children}: StateContextProviderProps) => { } }, [postPopUp]); - const startQuery = useCallback(({ - isCaseSensitive, - isRegex, - queryString, - }: QueryArgs) => { + const startQuery = useCallback((queryArgs: QueryArgs) => { setQueryResults(STATE_DEFAULT.queryResults); if (null === mainWorkerRef.current) { console.error("Unexpected null mainWorkerRef.current"); return; } - workerPostReq(mainWorkerRef.current, WORKER_REQ_CODE.START_QUERY, { - queryString: queryString, - isRegex: isRegex, - isCaseSensitive: isCaseSensitive, - }); + workerPostReq(mainWorkerRef.current, WORKER_REQ_CODE.START_QUERY, queryArgs); }, []); const exportLogs = useCallback(() => { diff --git a/src/services/LogFileManager/index.ts b/src/services/LogFileManager/index.ts index 10566999..b47b8baf 100644 --- a/src/services/LogFileManager/index.ts +++ b/src/services/LogFileManager/index.ts @@ -6,6 +6,10 @@ import { } from "../../typings/decoders"; import {MAX_V8_STRING_LENGTH} from "../../typings/js"; import {LogLevelFilter} from "../../typings/logs"; +import { + QueryArgs, + QueryResults, +} from "../../typings/query"; import { BeginLineNumToLogEventNumMap, CURSOR_CODE, @@ -13,7 +17,6 @@ import { CursorType, EMPTY_PAGE_RESP, FileSrcType, - QueryResults, WORKER_RESP_CODE, WorkerResp, } from "../../typings/worker"; @@ -286,11 +289,12 @@ class LogFileManager { * Creates a RegExp object based on the given query string and options, and starts querying the * first log chunk. * - * @param queryString - * @param isRegex - * @param isCaseSensitive + * @param queryArgs + * @param queryArgs.queryString + * @param queryArgs.isRegex + * @param queryArgs.isCaseSensitive */ - startQuery (queryString: string, isRegex: boolean, isCaseSensitive: boolean): void { + startQuery ({queryString, isRegex, isCaseSensitive}: QueryArgs): void { this.#queryId++; this.#queryCount = 0; diff --git a/src/services/MainWorker.ts b/src/services/MainWorker.ts index d7ce638d..cd37753b 100644 --- a/src/services/MainWorker.ts +++ b/src/services/MainWorker.ts @@ -4,9 +4,9 @@ import dayjsTimezone from "dayjs/plugin/timezone"; import dayjsUtc from "dayjs/plugin/utc"; import {LOG_LEVEL} from "../typings/logs"; +import {QueryResults} from "../typings/query"; import { MainWorkerReqMessage, - QueryResults, WORKER_REQ_CODE, WORKER_RESP_CODE, WorkerResp, @@ -124,18 +124,7 @@ onmessage = async (ev: MessageEvent) => { if (null === LOG_FILE_MANAGER) { throw new Error("Log file manager hasn't been initialized"); } - if ( - "string" !== typeof args.queryString || - "boolean" !== typeof args.isRegex || - "boolean" !== typeof args.isCaseSensitive - ) { - throw new Error("Invalid arguments for QUERY_LOG"); - } - LOG_FILE_MANAGER.startQuery( - args.queryString, - args.isRegex, - args.isCaseSensitive - ); + LOG_FILE_MANAGER.startQuery(args); break; default: console.error(`Unexpected ev.data: ${JSON.stringify(ev.data)}`); diff --git a/src/typings/query.ts b/src/typings/query.ts new file mode 100644 index 00000000..f3a64c36 --- /dev/null +++ b/src/typings/query.ts @@ -0,0 +1,28 @@ +const QUERY_PROGRESS_VALUE_MIN = 0; +const QUERY_PROGRESS_VALUE_MAX = 1; + +interface QueryArgs { + queryString: string; + isCaseSensitive: boolean; + isRegex: boolean; +} + +type TextRange = [number, number]; + +interface QueryResultsType { + logEventNum: number; + message: string; + matchRange: TextRange; +} + +type QueryResults = Map; + +export { + QUERY_PROGRESS_VALUE_MAX, + QUERY_PROGRESS_VALUE_MIN, +}; +export type { + QueryArgs, + QueryResults, + QueryResultsType, +}; diff --git a/src/typings/worker.ts b/src/typings/worker.ts index 7cdcf1a8..1333c19d 100644 --- a/src/typings/worker.ts +++ b/src/typings/worker.ts @@ -7,6 +7,7 @@ import { LOG_LEVEL, LogLevelFilter, } from "./logs"; +import {QueryResults} from "./query"; /** @@ -106,25 +107,6 @@ type WorkerReqMap = { }, }; -interface QueryArgs { - queryString: string; - isCaseSensitive: boolean; - isRegex: boolean; -} - -type TextRange = [number, number]; - -interface QueryResultsType { - logEventNum: number; - message: string; - matchRange: TextRange; -} - -type QueryResults = Map; - -const QUERY_PROGRESS_INIT = 0; -const QUERY_PROGRESS_DONE = 1; - type WorkerRespMap = { [WORKER_RESP_CODE.CHUNK_DATA]: { logs: string @@ -186,8 +168,6 @@ export { CURSOR_CODE, EMPTY_PAGE_RESP, EVENT_POSITION_ON_PAGE, - QUERY_PROGRESS_DONE, - QUERY_PROGRESS_INIT, WORKER_REQ_CODE, WORKER_RESP_CODE, }; @@ -198,9 +178,6 @@ export type { FileSrcType, MainWorkerReqMessage, MainWorkerRespMessage, - QueryArgs, - QueryResults, - QueryResultsType, WorkerReq, WorkerResp, }; From 6b509123620e4cfaa3220ce053334dc5e7da57b3 Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:13:15 -0500 Subject: [PATCH 5/9] fix import issue --- .../Sidebar/SidebarTabs/SearchTabPanel/ResultsGroup.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/ResultsGroup.tsx b/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/ResultsGroup.tsx index 28e1ce4a..b1751f4c 100644 --- a/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/ResultsGroup.tsx +++ b/src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/ResultsGroup.tsx @@ -17,7 +17,7 @@ import { import DescriptionOutlinedIcon from "@mui/icons-material/DescriptionOutlined"; -import {QueryResultsType} from "../../../../../typings/worker"; +import {QueryResultsType} from "../../../../../typings/query"; import Result from "./Result"; import "./ResultsGroup.css"; From 332b26903fc658df9d8878b8011bd82cb6a57438 Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:02:58 -0500 Subject: [PATCH 6/9] Apply suggestions from code review Co-authored-by: Junhao Liao --- src/typings/query.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/typings/query.ts b/src/typings/query.ts index f3a64c36..27131739 100644 --- a/src/typings/query.ts +++ b/src/typings/query.ts @@ -1,6 +1,3 @@ -const QUERY_PROGRESS_VALUE_MIN = 0; -const QUERY_PROGRESS_VALUE_MAX = 1; - interface QueryArgs { queryString: string; isCaseSensitive: boolean; @@ -17,12 +14,15 @@ interface QueryResultsType { type QueryResults = Map; -export { - QUERY_PROGRESS_VALUE_MAX, - QUERY_PROGRESS_VALUE_MIN, -}; +const QUERY_PROGRESS_VALUE_MIN = 0; +const QUERY_PROGRESS_VALUE_MAX = 1; + export type { QueryArgs, QueryResults, QueryResultsType, }; +export { + QUERY_PROGRESS_VALUE_MAX, + QUERY_PROGRESS_VALUE_MIN, +}; From 139c7c3615801b4bc2722401a3035143f9ca7572 Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:40:26 -0500 Subject: [PATCH 7/9] throws error in front end if the query regex string is not valid --- src/services/LogFileManager/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/services/LogFileManager/index.ts b/src/services/LogFileManager/index.ts index b47b8baf..a97af344 100644 --- a/src/services/LogFileManager/index.ts +++ b/src/services/LogFileManager/index.ts @@ -293,6 +293,7 @@ class LogFileManager { * @param queryArgs.queryString * @param queryArgs.isRegex * @param queryArgs.isCaseSensitive + * @throws {Error} if the query regex string is invalid. */ startQuery ({queryString, isRegex, isCaseSensitive}: QueryArgs): void { this.#queryId++; @@ -314,9 +315,16 @@ class LogFileManager { const regexFlags = isCaseSensitive ? "" : "i"; - const queryRegex = new RegExp(regexPattern, regexFlags); - this.#queryChunkAndScheduleNext(this.#queryId, 0, queryRegex); + try { + const queryRegex = new RegExp(regexPattern, regexFlags); + this.#queryChunkAndScheduleNext(this.#queryId, 0, queryRegex); + } catch (e) { + if (e instanceof SyntaxError) { + console.error("Invalid regular expression:", e); + } + throw e; + } } /** From 05a3219a300d8cefb3d65d50dcf96ed2e328368e Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:48:26 -0500 Subject: [PATCH 8/9] amend error type --- src/services/LogFileManager/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/LogFileManager/index.ts b/src/services/LogFileManager/index.ts index a97af344..328d8c90 100644 --- a/src/services/LogFileManager/index.ts +++ b/src/services/LogFileManager/index.ts @@ -293,7 +293,7 @@ class LogFileManager { * @param queryArgs.queryString * @param queryArgs.isRegex * @param queryArgs.isCaseSensitive - * @throws {Error} if the query regex string is invalid. + * @throws {SyntaxError} if the query regex string is invalid. */ startQuery ({queryString, isRegex, isCaseSensitive}: QueryArgs): void { this.#queryId++; From db5e7009fedf1c60cd03b6796a30539a12306526 Mon Sep 17 00:00:00 2001 From: Henry8192 <50559854+Henry8192@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:54:29 -0500 Subject: [PATCH 9/9] Update src/typings/query.ts Co-authored-by: Junhao Liao --- src/typings/query.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/typings/query.ts b/src/typings/query.ts index 27131739..f252be43 100644 --- a/src/typings/query.ts +++ b/src/typings/query.ts @@ -17,6 +17,7 @@ type QueryResults = Map; const QUERY_PROGRESS_VALUE_MIN = 0; const QUERY_PROGRESS_VALUE_MAX = 1; + export type { QueryArgs, QueryResults,