Skip to content

Commit

Permalink
fix: Unknown file type descriptor no longer fatally fails
Browse files Browse the repository at this point in the history
  • Loading branch information
steilerDev committed Aug 6, 2023
1 parent 157b0ba commit e138994
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/src/app/error/codes/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export const NO_DISTANCE_TO_ROOT: ErrorStruct = buildErrorStruct(
);

export const UNKNOWN_FILETYPE_DESCRIPTOR: ErrorStruct = buildErrorStruct(
name, prefix, `UNKNOWN_FILE_TYPE_DESCRIPTOR`, `Unknown filetype descriptor, see GH issue 143`,
name, prefix, `UNKNOWN_FILE_TYPE_DESCRIPTOR`, `Unknown filetype descriptor, please report in GH issue 143`,
);

export const UNKNOWN_FILETYPE_EXTENSION: ErrorStruct = buildErrorStruct(
name, prefix, `UNKNOWN_FILETYPE_EXTENSION`, `Unknown filetype extension, see GH issue 143`,
name, prefix, `UNKNOWN_FILETYPE_EXTENSION`, `Unknown filetype extension, please report in GH issue 143`,
);

export const INVALID_FILE: ErrorStruct = buildErrorStruct(
Expand Down
2 changes: 1 addition & 1 deletion app/src/app/error/codes/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const name = `SyncError`;
const prefix = `SYNC`;

export const CONVERSION: ErrorStruct = buildErrorStruct(
name, prefix, `CONVERSION`, `Error while converting asset`,
name, prefix, `CONVERSION`, `Asset could not be converted - ignoring it`,
);

export const STASH_RETRIEVE: ErrorStruct = buildErrorStruct(
Expand Down
28 changes: 20 additions & 8 deletions app/src/app/event/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {Readable} from 'stream';
import os from 'os';
import {pEvent} from 'p-event';

/**
* List of errors that will never get reported
*/
const reportDenyList = [
ERR_SIGINT.code,
ERR_SIGTERM.code,
Expand All @@ -22,6 +25,13 @@ const reportDenyList = [
AUTH_ERR.UNAUTHORIZED.code, // Only happens if username/password don't match
];

/**
* List of errors that will get reported, even though it's only a warning
*/
const reportAllowList = [
LIBRARY_ERR.UNKNOWN_FILETYPE_DESCRIPTOR.code
]

const BACKTRACE_SUBMISSION = {
DOMAIN: `https://submit.backtrace.io`,
UNIVERSE: `steilerdev`,
Expand Down Expand Up @@ -96,15 +106,17 @@ export class ErrorHandler {

let message = _err.getDescription();

const rootErrorCode = _err.getRootErrorCode(true);

// Report error and append error code
if (_err.sev === `FATAL`) { // Report only fatal errors
const rootErrorCode = _err.getRootErrorCode(true);
if (reportDenyList.indexOf(rootErrorCode) === -1) { // Report only, if root error code is not in deny list
const errorId = await this.reportError(_err);
message += ` (Error Code: ${errorId})`;
} else {
message += ` (Not reporting ${rootErrorCode})`;
}
if (
(_err.sev === `FATAL` || reportAllowList.indexOf(rootErrorCode) > -1) && // Report fatal errors and errors in allow list
reportDenyList.indexOf(rootErrorCode) === -1 // Exclude errors in deny list
) {
const errorId = await this.reportError(_err);
message += ` (Error Code: ${errorId})`;
} else {
message += ` (Not reporting ${rootErrorCode})`;
}

if (this.verbose && Object.keys(_err.context).length > 0) {
Expand Down
9 changes: 6 additions & 3 deletions app/src/lib/sync-engine/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {CPLAlbum, CPLAsset, CPLMaster} from "../icloud/icloud-photos/query-parse
import {Album} from "../photos-library/model/album.js";
import {Asset, AssetType} from "../photos-library/model/asset.js";
import {PEntity, PLibraryEntities, PLibraryProcessingQueues} from "../photos-library/model/photos-entity.js";
import { ResourceManager } from "../resource-manager/resource-manager.js";
import { iCPSEventError } from "../resource-manager/events.js";

/**
* This object exposes various static helpers required to perform a sync
Expand Down Expand Up @@ -64,11 +66,12 @@ function convertCPLAssets(cplAssets: CPLAsset[], cplMasters: CPLMaster[]): Asset
remoteAssets.push(Asset.fromCPL(asset.resource, asset.resourceType, origExt, asset.modified, origFilename, AssetType.EDIT, asset.recordName, asset.favorite, asset.zoneName));
}
} catch (err) {
// In case missing filetype descriptor is thrown, adding asset context to error
throw new iCPSError(SYNC_ERR.CONVERSION)
ResourceManager.emit(iCPSEventError.HANDLER_EVENT, new iCPSError(SYNC_ERR.CONVERSION)
.setWarning()
.addCause(err)
.addContext(`cplAsset`, asset)
.addContext(`cplMaster`, master);
.addContext(`cplMaster`, master)
)
}
});
return remoteAssets;
Expand Down

0 comments on commit e138994

Please sign in to comment.