mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
incr: add logUnexpected
- prevent undefined rootType, log it instead
This commit is contained in:
parent
69bf6a080d
commit
8d3d0a29ee
@ -29,6 +29,7 @@ import { Field } from 'schemas/types';
|
||||
import { fyo } from 'src/initFyo';
|
||||
import { getMapFromList } from 'utils';
|
||||
import { QueryFilter } from 'utils/db/types';
|
||||
import { logUnexpected } from 'utils/misc';
|
||||
|
||||
export const ACC_NAME_WIDTH = 2;
|
||||
export const ACC_BAL_WIDTH = 1.25;
|
||||
@ -167,6 +168,14 @@ export abstract class AccountReport extends LedgerReport {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!accountMap[entry.account]) {
|
||||
logUnexpected({
|
||||
message: 'accountMap[entry.account] is undefined',
|
||||
more: { entry },
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
const totalBalance = valueMap.get(key!)?.balance ?? 0;
|
||||
const balance = (entry.debit ?? 0) - (entry.credit ?? 0);
|
||||
const rootType = accountMap[entry.account].rootType;
|
||||
|
@ -17,7 +17,7 @@ function shouldNotStore(error: Error) {
|
||||
return !shouldLog;
|
||||
}
|
||||
|
||||
async function reportError(errorLogObj: ErrorLog) {
|
||||
export async function sendError(errorLogObj: ErrorLog) {
|
||||
if (!errorLogObj.stack) {
|
||||
return;
|
||||
}
|
||||
@ -30,13 +30,14 @@ async function reportError(errorLogObj: ErrorLog) {
|
||||
version: fyo.store.appVersion,
|
||||
language: fyo.store.language,
|
||||
instance_id: fyo.store.instanceId,
|
||||
device_id: fyo.store.deviceId,
|
||||
open_count: fyo.store.openCount,
|
||||
country_code: fyo.singles.SystemSettings?.countryCode,
|
||||
more: stringifyCircular(errorLogObj.more ?? {}),
|
||||
};
|
||||
|
||||
if (fyo.store.isDevelopment) {
|
||||
console.log('reportError', body);
|
||||
console.log('sendError', body);
|
||||
}
|
||||
|
||||
await ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body));
|
||||
@ -84,7 +85,7 @@ export async function handleError(
|
||||
|
||||
const errorLogObj = getErrorLogObject(error, more ?? {});
|
||||
|
||||
await reportError(errorLogObj);
|
||||
await sendError(errorLogObj);
|
||||
const toastProps = getToastProps(errorLogObj);
|
||||
await showToast(toastProps);
|
||||
}
|
||||
@ -250,5 +251,9 @@ function getErrorLabel(error: Error) {
|
||||
return t`Error`;
|
||||
}
|
||||
|
||||
if (name === 'ToDebugError') {
|
||||
return t`Error`;
|
||||
}
|
||||
|
||||
return t`Error`;
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { ConfigKeys } from 'fyo/core/types';
|
||||
import { DateTime } from 'luxon';
|
||||
import { IPC_ACTIONS } from 'utils/messages';
|
||||
import { CUSTOM_EVENTS, IPC_ACTIONS } from 'utils/messages';
|
||||
import { UnexpectedLogObject } from 'utils/types';
|
||||
import { App as VueApp, createApp } from 'vue';
|
||||
import App from './App.vue';
|
||||
import Badge from './components/Badge.vue';
|
||||
import FeatherIcon from './components/FeatherIcon.vue';
|
||||
import { getErrorHandled, handleError } from './errorHandling';
|
||||
import { getErrorHandled, handleError, sendError } from './errorHandling';
|
||||
import { fyo } from './initFyo';
|
||||
import { outsideClickDirective } from './renderer/helpers';
|
||||
import registerIpcRendererListeners from './renderer/registerIpcRendererListeners';
|
||||
@ -72,6 +73,16 @@ function setErrorHandlers(app: VueApp) {
|
||||
handleError(true, error, { message, source, lineno, colno });
|
||||
};
|
||||
|
||||
window.onunhandledrejection = (event: PromiseRejectionEvent) => {
|
||||
const error = event.reason;
|
||||
handleError(true, error).catch((err) => console.error(err));
|
||||
};
|
||||
|
||||
window.addEventListener(CUSTOM_EVENTS.LOG_UNEXPECTED, (event) => {
|
||||
const details = (event as CustomEvent)?.detail as UnexpectedLogObject;
|
||||
sendError(details);
|
||||
});
|
||||
|
||||
app.config.errorHandler = (err, vm, info) => {
|
||||
const more: Record<string, unknown> = {
|
||||
info,
|
||||
|
@ -46,4 +46,5 @@ export enum DB_CONN_FAILURE {
|
||||
// events
|
||||
export enum CUSTOM_EVENTS {
|
||||
MAIN_PROCESS_ERROR = 'main-process-error',
|
||||
LOG_UNEXPECTED = 'log-unexpected',
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import countryInfo from '../fixtures/countryInfo.json';
|
||||
import { DateTime } from 'luxon';
|
||||
import { CountryInfoMap } from './types';
|
||||
import countryInfo from '../fixtures/countryInfo.json';
|
||||
import { CUSTOM_EVENTS } from './messages';
|
||||
import { CountryInfoMap, UnexpectedLogObject } from './types';
|
||||
|
||||
export function getCountryInfo(): CountryInfoMap {
|
||||
// @ts-ignore
|
||||
@ -34,3 +35,23 @@ export function getFiscalYear(date: string, isStart: boolean) {
|
||||
.plus({ year: [1, 2, 3].includes(today.month) ? 0 : 1 })
|
||||
.toISODate();
|
||||
}
|
||||
|
||||
export function logUnexpected(detail: Partial<UnexpectedLogObject>) {
|
||||
/**
|
||||
* Raises a custom event, it's lsitener is in renderer.ts
|
||||
* used to log unexpected occurances as errors.
|
||||
*/
|
||||
if (!window?.CustomEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
detail.name ??= 'LogUnexpected';
|
||||
detail.message ??= 'Logging an unexpected occurance';
|
||||
detail.stack ??= new Error().stack;
|
||||
detail.more ??= {};
|
||||
|
||||
const event = new window.CustomEvent(CUSTOM_EVENTS.LOG_UNEXPECTED, {
|
||||
detail,
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
}
|
||||
|
@ -24,3 +24,10 @@ export interface VersionParts {
|
||||
}
|
||||
|
||||
export type Creds = { errorLogUrl: string; telemetryUrl: string; tokenString: string };
|
||||
|
||||
export type UnexpectedLogObject = {
|
||||
name: string;
|
||||
message: string;
|
||||
stack: string;
|
||||
more: Record<string, unknown>;
|
||||
}
|
Loading…
Reference in New Issue
Block a user