Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 91e97e5

Browse files
committed
handler some errors
1 parent 2534e33 commit 91e97e5

File tree

6 files changed

+88
-66
lines changed

6 files changed

+88
-66
lines changed

src/DatabaseView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class DatabaseView extends TextFileView implements HoverParent {
188188
// Render database
189189
const table = createDatabase(tableProps);
190190
this.rootContainer.render(table);
191+
this.diskConfig.saveOnDisk();
191192
LOGGER.info(`<=initDatabase ${this.file.path}`);
192193
} catch (e: unknown) {
193194
LOGGER.error(`initDatabase ${this.file.path}`, e);
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { LocalSettings } from "cdm/SettingsModel";
22
import { FormulaGenerator } from "automations/FormulaGenerator";
3+
import { AutomationError, showDBError } from "errors/ErrorTypes";
34

45
export async function obtainFormulasFromFolder(config: LocalSettings) {
5-
const generator = new FormulaGenerator(config);
6-
return await generator.generate_object();
6+
try {
7+
const generator = new FormulaGenerator(config);
8+
return await generator.generate_object();
9+
} catch (e) {
10+
showDBError(AutomationError.LoadFormulas, e);
11+
return {};
12+
}
713
}
814

src/errors/ErrorTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ export const EditionError: DBErrorTypeEnum = Object.freeze({
2323
error: `Error reading yaml file`,
2424
solution: `https://rafaelgb.github.io/obsidian-db-folder/faq/#possible-edition-issues-while-you-are-saving-a-cell-change`,
2525
}
26+
});
27+
28+
export const AutomationError: DBErrorTypeEnum = Object.freeze({
29+
LoadFormulas: {
30+
error: `Error loading formulas`,
31+
solution: `check your js files code`
32+
},
2633
});

src/parsers/handlers/marshall/MarshallColumnsHandler.ts

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { YamlHandlerResponse } from 'cdm/MashallModel';
33
import { RowSelectOption } from 'cdm/ComponentsModel';
44
import { InputType, DEFAULT_COLUMN_CONFIG } from 'helpers/Constants';
55
import { AbstractYamlHandler } from 'parsers/handlers/marshall/AbstractYamlPropertyHandler';
6+
import { RowType } from 'cdm/RowTypeModel';
67

78
export class MarshallColumnsHandler extends AbstractYamlHandler {
89
handlerName: string = 'columns';
@@ -12,16 +13,7 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
1213
if (!yaml.columns) {
1314
// if columns is not defined, load default
1415
this.addError(`There was not columns in yaml. Default will be loaded`);
15-
yaml.columns = {
16-
Column1: {
17-
input: InputType.TEXT,
18-
accessorKey: 'Column1',
19-
key: 'Column1',
20-
label: 'Column 1',
21-
position: 1,
22-
config: DEFAULT_COLUMN_CONFIG
23-
}
24-
};
16+
yaml.columns = {};
2517
}
2618
// Check every column
2719
Object.keys(yaml.columns)
@@ -32,7 +24,7 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
3224
this.addError(`There was not input in column ${key}`);
3325
column.input = InputType.TEXT;
3426
} else {
35-
column = marshallParticularInputInfo(column);
27+
column = this.marshallParticularInputInfo(column);
3628
// PARTICULAR INPUT INFO
3729
}
3830
if (!column.accessorKey) {
@@ -48,13 +40,10 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
4840
column.label = key;
4941
}
5042

51-
if (column.skipPersist === undefined) {
52-
column.skipPersist = false;
53-
}
5443

55-
if (column.isHidden === undefined) {
56-
column.isHidden = false;
57-
}
44+
column.skipPersist = this.parseBoolean(column.skipPersist);
45+
46+
column.isHidden = this.parseBoolean(column.isHidden);
5847

5948
if (column.sortIndex === undefined || typeof column.sortIndex !== 'number') {
6049
column.sortIndex = -1;
@@ -65,62 +54,80 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
6554
column.config = DEFAULT_COLUMN_CONFIG;
6655
} else {
6756
// General config
68-
if (column.config.isInline === undefined) {
69-
column.config.isInline = DEFAULT_COLUMN_CONFIG.isInline;
70-
}
71-
column = marshallParticularConfigInfo(column);
57+
column.config.isInline = this.parseBoolean(column.config.isInline);
58+
column = this.marshallParticularConfigInfo(column);
7259
}
7360
// Update mashaller response
7461
yaml.columns[key] = column;
7562
});
7663
handlerResponse.yaml = yaml;
7764
return this.goNext(handlerResponse);
7865
}
79-
}
8066

81-
function marshallParticularInputInfo(column: DatabaseColumn): DatabaseColumn {
82-
switch (column.input) {
83-
case InputType.SELECT:
84-
case InputType.TAGS:
85-
if (!column.options || !Array.isArray(column.options)) {
86-
column.options = [];
87-
} else {
88-
// Control undefined or null labels and backgroundColors
89-
column.options = column.options.filter((option: RowSelectOption) => {
90-
return option.backgroundColor
91-
&& option.label
92-
&& option.label !== ''
93-
&& option.backgroundColor !== '';
94-
// Control duplicates labels in options
95-
}).filter((option: RowSelectOption, index: number, self: RowSelectOption[]) => {
96-
return self.findIndex((t: RowSelectOption) => {
97-
return t.label === option.label;
98-
}) === index;
99-
}
100-
);
101-
}
102-
break;
67+
parseBoolean(value: RowType, defaultValue = false): boolean {
68+
if (value === undefined || value === null) {
69+
return defaultValue;
70+
}
71+
72+
if (typeof value === 'boolean') {
73+
return value;
74+
}
75+
76+
if (value === 'true') {
77+
return true;
78+
} else if (value === 'false') {
79+
return false;
80+
}
81+
return defaultValue;
82+
}
83+
84+
parseNumber(value: RowType, defaultValue = 0): number {
85+
if (value === undefined || value === null) {
86+
return defaultValue;
87+
}
88+
if (typeof value === 'number') {
89+
return value;
90+
}
91+
return Number(value);
92+
}
93+
94+
marshallParticularConfigInfo(column: DatabaseColumn): DatabaseColumn {
95+
switch (column.input) {
96+
case InputType.TEXT:
97+
column.config.enable_media_view = this.parseBoolean(column.config.enable_media_view, DEFAULT_COLUMN_CONFIG.enable_media_view);
98+
column.config.media_width = this.parseNumber(column.config.media_width, DEFAULT_COLUMN_CONFIG.media_width);
99+
column.config.media_height = this.parseNumber(column.config.media_height, DEFAULT_COLUMN_CONFIG.media_height);
100+
break;
101+
case InputType.TASK:
102+
column.config.task_hide_completed = this.parseBoolean(column.config.task_hide_completed, DEFAULT_COLUMN_CONFIG.task_hide_completed);
103+
break;
104+
}
105+
return column;
103106
}
104-
return column;
105-
}
106107

107-
function marshallParticularConfigInfo(column: DatabaseColumn): DatabaseColumn {
108-
switch (column.input) {
109-
case InputType.TEXT:
110-
if (column.config.enable_media_view === undefined) {
111-
column.config.enable_media_view = DEFAULT_COLUMN_CONFIG.enable_media_view;
112-
}
113-
if (column.config.media_width === undefined) {
114-
column.config.media_width = DEFAULT_COLUMN_CONFIG.media_width;
115-
}
116-
if (column.config.media_height === undefined) {
117-
column.config.media_height = DEFAULT_COLUMN_CONFIG.media_height;
118-
}
119-
case InputType.TASK:
120-
if (column.config.task_hide_completed === undefined) {
121-
column.config.task_hide_completed = DEFAULT_COLUMN_CONFIG.task_hide_completed;
108+
marshallParticularInputInfo(column: DatabaseColumn): DatabaseColumn {
109+
switch (column.input) {
110+
case InputType.SELECT:
111+
case InputType.TAGS:
112+
if (!column.options || !Array.isArray(column.options)) {
113+
column.options = [];
114+
} else {
115+
// Control undefined or null labels and backgroundColors
116+
column.options = column.options.filter((option: RowSelectOption) => {
117+
return option.backgroundColor
118+
&& option.label
119+
&& option.label !== ''
120+
&& option.backgroundColor !== '';
121+
// Control duplicates labels in options
122+
}).filter((option: RowSelectOption, index: number, self: RowSelectOption[]) => {
123+
return self.findIndex((t: RowSelectOption) => {
124+
return t.label === option.label;
125+
}) === index;
126+
}
127+
);
128+
}
122129
break;
123-
}
130+
}
131+
return column;
124132
}
125-
return column;
126133
}

src/services/DatabaseInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class DatabaseInfo {
4949
}
5050

5151
this.yaml = response.yaml;
52-
await this.saveOnDisk();
52+
//await this.saveOnDisk();
5353
LOGGER.info(`<=initDatabaseconfigYaml`);
5454
}
5555

src/settings/handlers/automation/FormulaJSFolderHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class FormulaJSFolderHandler extends AbstractSettingsHandler {
66
settingTitle: string = 'Select the source of your formula JS files';
77
handle(settingHandlerResponse: SettingHandlerResponse): SettingHandlerResponse {
88
const { settingsManager, containerEl, view, local } = settingHandlerResponse;
9+
910
const formula_folder_promise = async (value: string): Promise<void> => {
1011
if (local) {
1112
// update settings

0 commit comments

Comments
 (0)