Skip to content

Commit

Permalink
Updated error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Nov 11, 2024
1 parent 540fec9 commit bd7ae19
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default tseslint.config(
{
rules: {
'@typescript-eslint/no-confusing-void-expression': 'off',
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'off',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
Expand Down
3 changes: 2 additions & 1 deletion packages/tokenizer/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export type TokenNode = ObjectNode | ArrayNode | StringNode | NumberNode | Boole

export interface ErrorNode {
type: 'error';
scope: 'jq' | 'tokenizer';
scope: 'jq' | 'tokenizer' | 'worker';
error: string;
stack?: string;
}

export type TokenizerResponse = TokenNode | TupleNode | ErrorNode;
18 changes: 16 additions & 2 deletions src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@ chrome.runtime.onMessage.addListener(function (message: TokenizeParams | JqParam
if (is(message, 'tokenize')) {
tokenize(message.json)
.then(sendResponse)
.catch((err: unknown) => console.error(err));
.catch((err: Error) =>
sendResponse({
type: 'error',
scope: 'worker',
stack: err.stack,
error: err.message,
})
);

return true;
}

if (is(message, 'jq')) {
jq(message.json, message.query)
.then(sendResponse)
.catch((err: unknown) => console.error(err));
.catch((err: Error) =>
sendResponse({
type: 'error',
scope: 'worker',
stack: err.stack,
error: err.message,
})
);

return true;
}
Expand Down
5 changes: 2 additions & 3 deletions src/background/helpres.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { JqParams, Message, TokenizeParams } from '@core/background';


interface Types {
'jq': JqParams,
'tokenize': TokenizeParams,
jq: JqParams;
tokenize: TokenizeParams;
}

export const is = <T extends Message['action']>(message: object, type: T): message is Types[T] => {
Expand Down
1 change: 0 additions & 1 deletion src/core/background/jq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ import { TokenizerResponse } from '@packages/tokenizer';
export const jq = async (json: string, query: string): Promise<TokenizerResponse> => {
return sendMessage<JqParams, TokenizerResponse>({ action: 'jq', json, query });
};

2 changes: 1 addition & 1 deletion src/core/background/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TokenizerResponse } from "@packages/tokenizer";
import { TokenizerResponse } from '@packages/tokenizer';

export interface TokenizeParams {
action: 'tokenize';
Expand Down
1 change: 0 additions & 1 deletion src/core/background/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ import { TokenizerResponse } from '@packages/tokenizer';
export const tokenize = async (json: string): Promise<TokenizerResponse> => {
return sendMessage<TokenizeParams, TokenizerResponse>({ action: 'tokenize', json });
};

0 comments on commit bd7ae19

Please sign in to comment.