From f996e8978181f3c1c028e0f022471a9c0dbd766f Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 11 Mar 2024 16:45:50 +0100 Subject: [PATCH 1/2] Removed used of `fs-extra` from @tryghost/logging ref SLO-14 ref https://linear.app/tryghost/issue/SLO-14/improved-speed-of-migratejs-script - fs-extra can be a really heavy library when you're trying to stay lean - we don't need it here because `fs` natively comes with a sync `exists` method - this replaces `fs-extra` with `fs` --- packages/logging/lib/GhostLogger.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/logging/lib/GhostLogger.js b/packages/logging/lib/GhostLogger.js index 3d9c9552..d14a438a 100644 --- a/packages/logging/lib/GhostLogger.js +++ b/packages/logging/lib/GhostLogger.js @@ -5,7 +5,7 @@ const isObject = require('lodash/isObject'); const isEmpty = require('lodash/isEmpty'); const includes = require('lodash/includes'); const bunyan = require('bunyan'); -const fs = require('fs-extra'); +const fs = require('fs'); const jsonStringifySafe = require('json-stringify-safe'); /** @@ -287,7 +287,7 @@ class GhostLogger { const sanitizedDomain = this.domain.replace(/[^\w]/gi, '_'); // CASE: target log folder does not exist, show warning - if (!fs.pathExistsSync(this.path)) { + if (!fs.existsSync(this.path)) { this.error('Target log folder does not exist: ' + this.path); return; } From e6b07ac23825aa684551cd5e97b8a6707311dbf6 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 11 Mar 2024 16:50:29 +0100 Subject: [PATCH 2/2] Added RangeNotSatisfiableError error ref ENG-729 ref https://linear.app/tryghost/issue/ENG-729/incorrect-range-header-leads-to-http-500-errors - this will be used when the content Ghost is trying to serve cannot be satisfied for the provided range --- packages/errors/src/errors.ts | 11 +++++++++++ packages/errors/test/errors.test.ts | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/errors/src/errors.ts b/packages/errors/src/errors.ts index 8be63a23..2bd84146 100644 --- a/packages/errors/src/errors.ts +++ b/packages/errors/src/errors.ts @@ -137,6 +137,17 @@ export class RequestNotAcceptableError extends GhostError { } } +export class RangeNotSatisfiableError extends GhostError { + constructor(options: GhostErrorOptions = {}) { + super(mergeOptions(options, { + statusCode: 416, + errorType: 'RangeNotSatisfiableError', + message: 'Range not satisfiable for provided Range header.', + hideStack: true + })); + } +} + export class RequestEntityTooLargeError extends GhostError { constructor(options: GhostErrorOptions = {}) { super(mergeOptions(options, { diff --git a/packages/errors/test/errors.test.ts b/packages/errors/test/errors.test.ts index ed3e61cd..0d6e929e 100644 --- a/packages/errors/test/errors.test.ts +++ b/packages/errors/test/errors.test.ts @@ -488,6 +488,15 @@ Line 2 - Help`); error.hideStack.should.be.false(); }); + it('RangeNotSatisfiableError', function () { + const error = new errors.RangeNotSatisfiableError(); + error.statusCode.should.eql(416); + error.level.should.eql('normal'); + error.errorType.should.eql('RangeNotSatisfiableError'); + error.message.should.eql('Range not satisfiable for provided Range header.'); + error.hideStack.should.be.true(); + }); + it('TokenRevocationError', function () { const error = new errors.TokenRevocationError(); error.statusCode.should.eql(503);