Skip to content

Commit 7bb773d

Browse files
committed
Add error logging to the Attachment model
1 parent cae7461 commit 7bb773d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

app/models/attachment.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { TooManyRequestsException } from '../support/exceptions';
2020
const mvAsync = util.promisify(mv);
2121

2222
const debug = createDebug('freefeed:model:attachment');
23+
const debugError = createDebug('freefeed:model:attachment:error');
2324

2425
export function addModel(dbAdapter) {
2526
return class Attachment {
@@ -99,7 +100,10 @@ export function addModel(dbAdapter) {
99100
};
100101

101102
if (!entry.url) {
102-
debug(`no URL for image size ${variant} of attachment ${this.id}`, this._imageSizes);
103+
debugError(
104+
`no URL for image size ${variant} of attachment ${this.id}`,
105+
this._imageSizes,
106+
);
103107
}
104108
}
105109
}
@@ -148,7 +152,7 @@ export function addModel(dbAdapter) {
148152

149153
if (inProgressMedia >= limit) {
150154
// User has too many media in progress, don't process any more
151-
debug(
155+
debugError(
152156
`user ${user.id} has too many attachments in progress, aborting the ${filePath} processing`,
153157
);
154158
await Promise.all(Object.values(files).map((file) => fs.unlink(file.path)));
@@ -211,7 +215,7 @@ export function addModel(dbAdapter) {
211215
});
212216

213217
if (!files['']) {
214-
debug(`no original file to upload (${this.id})`);
218+
debugError(`no original file to upload (${this.id})`);
215219
throw new Error('No original file to upload');
216220
}
217221

@@ -224,7 +228,7 @@ export function addModel(dbAdapter) {
224228
// Update data
225229
await dbAdapter.updateAttachment(this.id, { ...mediaData, updatedAt: 'now' });
226230
} catch (err) {
227-
debug(`finalizeCreation error: ${err.message}, treat file as 'general' type`);
231+
debugError(`finalizeCreation error: ${err.message}, treat file as 'general' type`);
228232

229233
const { size: fileSize } = await fs.stat(filePath);
230234
const ext = extname(this.fileName)
@@ -488,7 +492,7 @@ export function addModel(dbAdapter) {
488492
} catch (err) {
489493
// Exiftool is failed, so the file was not updated and we cannot do
490494
// anymore here
491-
debug(`sanitizeOriginal: cannot sanitize attachment ${this.id}: ${err.message}`);
495+
debugError(`sanitizeOriginal: cannot sanitize attachment ${this.id}: ${err.message}`);
492496
Raven.captureException(err, {
493497
extra: {
494498
err: `sanitizeOriginal: cannot sanitize attachment ${this.id}`,
@@ -540,7 +544,7 @@ export function addModel(dbAdapter) {
540544
await fs.unlink(localFile);
541545
} catch (err) {
542546
if (err.code !== 'ENOENT') {
543-
debug(`sanitizeOriginal: cannot remove temporary file: ${localFile}`);
547+
debugError(`sanitizeOriginal: cannot remove temporary file: ${localFile}`);
544548
Raven.captureException(err, {
545549
extra: { err: `sanitizeOriginal: cannot remove temporary file: ${localFile}` },
546550
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "freefeed-server",
44
"description": "FreeFeed is an open source FriendFeed clone (yes, it is free and open!) based on Pepyatka open-source FriendFeed clone (yes, that one is also free and open). Basically, this is a social real-time feed aggregator that allows you to share cute kittens, coordinate upcoming events, discuss any other cool stuff on the Internet or setup a private Pepyatka instance in your company.",
55
"homepage": "https://freefeed.net",
6-
"version": "2.23.3",
6+
"version": "2.23.4",
77
"private": true,
88
"scripts": {
99
"start": "cross-env TZ=UTC yarn babel index.js",

0 commit comments

Comments
 (0)