mirror of
https://github.com/frappe/books.git
synced 2024-11-08 23:00:56 +00:00
fix(ux): prevent unable to acquire conn
This commit is contained in:
parent
d0fe62946c
commit
5f66cfe5d5
53
src/App.vue
53
src/App.vue
@ -50,7 +50,11 @@ import SetupWizard from './pages/SetupWizard/SetupWizard.vue';
|
||||
import setupInstance from './setup/setupInstance';
|
||||
import { SetupWizardOptions } from './setup/types';
|
||||
import './styles/index.css';
|
||||
import { connectToDatabase, dbErrorActionSymbols } from './utils/db';
|
||||
import {
|
||||
connectToDatabase,
|
||||
dbErrorActionSymbols,
|
||||
handleDatabaseConnectionError,
|
||||
} from './utils/db';
|
||||
import { initializeInstance } from './utils/initialization';
|
||||
import * as injectionKeys from './utils/injectionKeys';
|
||||
import { checkForUpdates } from './utils/ipcCalls';
|
||||
@ -191,20 +195,57 @@ export default defineComponent({
|
||||
return await this.handleConnectionFailed(error, actionSymbol);
|
||||
}
|
||||
|
||||
const setupComplete = await fyo.getValue(
|
||||
ModelNameEnum.AccountingSettings,
|
||||
'setupComplete'
|
||||
);
|
||||
const setupComplete = await this.getSetupComplete(filePath);
|
||||
if (typeof setupComplete === 'object') {
|
||||
return await this.handleConnectionFailed(
|
||||
setupComplete.error,
|
||||
setupComplete.actionSymbol
|
||||
);
|
||||
}
|
||||
|
||||
if (!setupComplete) {
|
||||
this.activeScreen = Screen.SetupWizard;
|
||||
return;
|
||||
}
|
||||
|
||||
await initializeInstance(filePath, false, countryCode, fyo);
|
||||
await this.initializeInstanceWithErrorHandling(filePath, countryCode);
|
||||
await updatePrintTemplates(fyo);
|
||||
await this.setDesk(filePath);
|
||||
},
|
||||
async getSetupComplete(dbPath: string) {
|
||||
try {
|
||||
return (await fyo.getValue(
|
||||
ModelNameEnum.AccountingSettings,
|
||||
'setupComplete'
|
||||
)) as boolean;
|
||||
} catch (error) {
|
||||
if (!(error instanceof Error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return {
|
||||
error,
|
||||
actionSymbol: await handleDatabaseConnectionError(error, dbPath),
|
||||
};
|
||||
}
|
||||
},
|
||||
async initializeInstanceWithErrorHandling(
|
||||
dbPath: string,
|
||||
countryCode: string
|
||||
) {
|
||||
try {
|
||||
return await initializeInstance(dbPath, false, countryCode, fyo);
|
||||
} catch (error) {
|
||||
if (!(error instanceof Error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
this.handleConnectionFailed(
|
||||
error,
|
||||
await handleDatabaseConnectionError(error, dbPath)
|
||||
);
|
||||
}
|
||||
},
|
||||
async handleConnectionFailed(error: Error, actionSymbol: symbol) {
|
||||
await this.showDbSelector();
|
||||
|
||||
|
@ -7,6 +7,7 @@ export const dbErrorActionSymbols = {
|
||||
|
||||
const dbErrors = {
|
||||
DirectoryDoesNotExist: 'directory does not exist',
|
||||
UnableToAcquireConnection: 'Unable to acquire a connection',
|
||||
} as const;
|
||||
|
||||
type Conn = {
|
||||
@ -27,26 +28,52 @@ export async function connectToDatabase(
|
||||
throw error;
|
||||
}
|
||||
|
||||
const actionSymbol = await handleDatabaseConnectionError(error, dbPath);
|
||||
|
||||
return { countryCode: '', error, actionSymbol };
|
||||
return {
|
||||
countryCode: '',
|
||||
error,
|
||||
actionSymbol: await handleDatabaseConnectionError(error, dbPath),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDatabaseConnectionError(error: Error, dbPath: string) {
|
||||
if (error.message?.includes(dbErrors.DirectoryDoesNotExist)) {
|
||||
export async function handleDatabaseConnectionError(
|
||||
error: Error,
|
||||
dbPath: string
|
||||
) {
|
||||
const message = error.message;
|
||||
if (typeof message !== 'string') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (message.includes(dbErrors.DirectoryDoesNotExist)) {
|
||||
return await handleDirectoryDoesNotExist(dbPath);
|
||||
}
|
||||
|
||||
if (message.includes(dbErrors.UnableToAcquireConnection)) {
|
||||
return await handleUnableToAcquireConnection(dbPath);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
async function handleUnableToAcquireConnection(dbPath: string) {
|
||||
return await showDbErrorDialog(
|
||||
t`Could not connect to database file ${dbPath}, please select the file manually`
|
||||
);
|
||||
}
|
||||
|
||||
async function handleDirectoryDoesNotExist(dbPath: string) {
|
||||
return await showDbErrorDialog(
|
||||
t`Directory for database file ${dbPath} does not exist, please select the file manually`
|
||||
);
|
||||
}
|
||||
|
||||
async function showDbErrorDialog(detail: string) {
|
||||
const { showDialog } = await import('src/utils/interactive');
|
||||
return await showDialog({
|
||||
type: 'error',
|
||||
title: t`Cannot Open File`,
|
||||
detail: t`Directory for file ${dbPath} does not exist`,
|
||||
detail,
|
||||
buttons: [
|
||||
{
|
||||
label: t`Select File`,
|
||||
|
Loading…
Reference in New Issue
Block a user