mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
fix: better loader functionality and error handling
This commit is contained in:
@@ -46,9 +46,10 @@ export abstract class FileModification {
|
||||
query: '?raw',
|
||||
import: 'default',
|
||||
});
|
||||
const patchPath = `./modifications/patches/${this.id}.patch`;
|
||||
const loader = patchResults[patchPath];
|
||||
|
||||
if (patchResults[`./modifications/patches/${this.id}.patch`]) {
|
||||
const loader = Object.values(patchResults)[0];
|
||||
if (typeof loader === 'function') {
|
||||
const fileContents = await loader();
|
||||
this.logger.debug(`Loaded pregenerated patch for ${this.id}`);
|
||||
if (typeof fileContents !== 'string') {
|
||||
@@ -56,9 +57,10 @@ export abstract class FileModification {
|
||||
return null;
|
||||
}
|
||||
return fileContents;
|
||||
} else {
|
||||
this.logger.warn('Could not load pregenerated patch for: ' + this.id);
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async applyPatch(patchContents: string): Promise<void> {
|
||||
|
||||
@@ -99,7 +99,7 @@ describe.sequential('FileModificationService', () => {
|
||||
const rolledBackContent = await fs.readFile(FIXTURE_PATH, 'utf-8');
|
||||
expect(rolledBackContent).toBe(ORIGINAL_CONTENT);
|
||||
|
||||
expect(mockLogger.error).not.toHaveBeenCalled();
|
||||
expect(mockLogger.warn).toHaveBeenCalledWith('Could not load pregenerated patch for: test');
|
||||
expect(mockLogger.log.mock.calls).toEqual([
|
||||
['RootTestModule dependencies initialized'],
|
||||
['Applying modification: test - Always Apply this mod'],
|
||||
@@ -126,9 +126,9 @@ describe.sequential('FileModificationService', () => {
|
||||
|
||||
// Now apply again and ensure the contents don't change
|
||||
await service.applyModification(mod);
|
||||
const errorMessage = mockLogger.error.mock.calls[0][0];
|
||||
const errorMessage = mockLogger.warn.mock.calls[0][0];
|
||||
expect(errorMessage).toContain(
|
||||
'Failed to apply patch to /app/src/unraid-api/unraid-file-modifier/modifications/__fixtures__/text-patch-file.txt'
|
||||
'Could not load pregenerated patch for: test'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user