• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bpatrik / pigallery2 / 8668205208

12 Apr 2024 09:31PM UTC coverage: 65.152% (+0.07%) from 65.085%
8668205208

Pull #885

github

bpatrik
Merge remote-tracking branch 'origin/bugfix/ext-config' into bugfix/ext-config
Pull Request #885: Improve extansion loading #847

1549 of 2703 branches covered (57.31%)

Branch coverage included in aggregate %.

4 of 5 new or added lines in 1 file covered. (80.0%)

4430 of 6474 relevant lines covered (68.43%)

13321.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.33
/src/backend/model/extension/ExtensionConfigWrapper.ts
1
import {IConfigClass} from 'typeconfig/common';
2
import {PrivateConfigClass} from '../../../common/config/private/PrivateConfigClass';
1✔
3
import {ConfigClassBuilder} from 'typeconfig/node';
1✔
4
import {ExtensionConfigTemplateLoader} from './ExtensionConfigTemplateLoader';
1✔
5
import {NotificationManager} from '../NotifocationManager';
1✔
6
import {ServerConfig} from '../../../common/config/private/PrivateConfig';
7
import {ConfigClassOptions} from 'typeconfig/src/decorators/class/IConfigClass';
8
import * as fs from 'fs';
1✔
9

10

11
const LOG_TAG = '[ExtensionConfigWrapper]';
1✔
12

13
/**
14
 * Wraps to original config and makes sure all extension related config is loaded
15
 */
16
export class ExtensionConfigWrapper {
1✔
17

18
  static async original(showDetailedError = false): Promise<PrivateConfigClass & IConfigClass> {
10✔
19
    const pc = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
10✔
20
    ExtensionConfigTemplateLoader.Instance.loadExtensionTemplates(pc);
10✔
21
    try {
10✔
22
      // make sure the config file exists by the time we load it.
23
      // TODO: remove this once typeconfig is fixed and can properly load defaults in arrays
24
      if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) {
10✔
25
        await pc.save();
3✔
26
      }
27

28
      await pc.load(); // loading the basic configs, but we do not know the extension config hierarchy yet
10✔
29

30
    } catch (e) {
31
      console.error(LOG_TAG, 'Error during loading config. Reverting to defaults.');
×
32
      console.error(e);
×
33
      if (showDetailedError) {
×
34
        console.error(LOG_TAG, 'This is most likely due to: 1) you added a bad configuration in the server.json OR 2) The configuration changed in the latest release.');
×
35
        NotificationManager.error('Can\'t load config. Reverting to default. This is most likely due to: 1) you added a bad configuration in the server.json OR 2) The configuration changed in the latest release.', (e.toString ? e.toString() : JSON.stringify(e)));
×
36
      }
37
    }
38
    return pc;
10✔
39
  }
40

41

42
  static originalSync(showDetailedError = false): PrivateConfigClass & IConfigClass {
×
43
    const pc = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
1✔
44
    ExtensionConfigTemplateLoader.Instance.loadExtensionTemplates(pc);
1✔
45
    try {
1✔
46
      // make sure the config file exists by the time we load it.
47
      // TODO: remove this once typeconfig is fixed and can properly load defaults in arrays
48
      if (!fs.existsSync((pc.__options as ConfigClassOptions<ServerConfig>).configPath)) {
1!
NEW
49
        pc.saveSync();
×
50
      }
51
      pc.loadSync(); // loading the basic configs, but we do not know the extension config hierarchy yet
1✔
52

53
    } catch (e) {
54
      console.error(LOG_TAG, 'Error during loading config. Reverting to defaults.');
×
55
      console.error(e);
×
56
      if (showDetailedError) {
×
57
        console.error(LOG_TAG, 'This is most likely due to: 1) you added a bad configuration in the server.json OR 2) The configuration changed in the latest release.');
×
58
        NotificationManager.error('Ca\'nt load config. Reverting to default. This is most likely due to: 1) you added a bad configuration in the server.json OR 2) The configuration changed in the latest release.', (e.toString ? e.toString() : JSON.stringify(e)));
×
59
      }
60
    }
61
    return pc;
1✔
62
  }
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc