Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/Deprecator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ describe('Deprecator', () => {
expect(logSpy).not.toHaveBeenCalled();
});

it('does not log deprecation for new default if logLevels.deprecation is silent', async () => {
deprecations = [{ optionKey: 'exampleKey', changeNewDefault: 'exampleNewDefault' }];

spyOn(Deprecator, '_getDeprecations').and.callFake(() => deprecations);
const logger = require('../lib/logger').logger;
const logSpy = spyOn(logger, 'warn').and.callFake(() => {});
await reconfigureServer({ logLevels: { deprecation: 'silent' } });
expect(logSpy).not.toHaveBeenCalled();
});

it('does not log deprecation for new default if logLevels.deprecation_exampleKey is silent', async () => {
deprecations = [{ optionKey: 'exampleKey', changeNewDefault: 'exampleNewDefault' }];

spyOn(Deprecator, '_getDeprecations').and.callFake(() => deprecations);
const logger = require('../lib/logger').logger;
const logSpy = spyOn(logger, 'warn').and.callFake(() => {});
await reconfigureServer({ logLevels: { deprecation_exampleKey: 'silent' } });
expect(logSpy).not.toHaveBeenCalled();
});

it('logs runtime deprecation', async () => {
const logger = require('../lib/logger').logger;
const logSpy = spyOn(logger, 'warn').and.callFake(() => {});
Expand Down
32 changes: 27 additions & 5 deletions src/Deprecator/Deprecator.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ class Deprecator {
const changeNewKey = deprecation.changeNewKey;

// If default will change, only throw a warning if option is not set
if (changeNewDefault != null && Utils.getNestedProperty(options, optionKey) == null) {
Deprecator._logOption({ optionKey, changeNewDefault, solution });
if (
changeNewDefault != null &&
Utils.getNestedProperty(options, optionKey) == null
) {
Deprecator._logOption({ optionKey, changeNewDefault, solution, options });
}

// If key will be removed or renamed, only throw a warning if option is set;
// skip if option is set to the resolved value that suppresses the deprecation
const resolvedValue = deprecation.resolvedValue;
const optionValue = Utils.getNestedProperty(options, optionKey);
if (changeNewKey != null && optionValue != null && optionValue !== resolvedValue) {
Deprecator._logOption({ optionKey, changeNewKey, solution });
Deprecator._logOption({ optionKey, changeNewKey, solution, options });
}
}
}
Expand Down Expand Up @@ -103,8 +106,9 @@ class Deprecator {
* message must not include the warning that the parameter is deprecated, that is
* automatically added to the message. It should only contain the instruction on how
* to resolve this warning.
* @param {Object} [options] The Parse Server options, used to determine log levels.
*/
static _logOption({ optionKey, envKey, changeNewKey, changeNewDefault, solution }) {
static _logOption({ optionKey, envKey, changeNewKey, changeNewDefault, solution, options }) {
const type = optionKey ? 'option' : 'environment key';
const key = optionKey ? optionKey : envKey;
const keyAction =
Expand All @@ -114,14 +118,32 @@ class Deprecator {
? `renamed to '${changeNewKey}'`
: `removed`;

// Determine the log level
const logLevels = (options && options.logLevels) || {};
let level = 'warn';
if (key && logLevels[`deprecation_${key}`]) {
level = logLevels[`deprecation_${key}`];
} else if (logLevels['deprecation']) {
level = logLevels['deprecation'];
}

if (level === 'silent') {
return;
}

// Compose message
let output = `DeprecationWarning: The Parse Server ${type} '${key}' `;
output += changeNewKey != null ? `is deprecated and will be ${keyAction} in a future version.` : '';
output += changeNewDefault
? `default will change to '${changeNewDefault}' in a future version.`
: '';
output += solution ? ` ${solution}` : '';
logger.warn(output);

if (typeof logger[level] === 'function') {
logger[level](output);
} else {
logger.warn(output);
}
Comment on lines +121 to +146

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Allow-list log levels before dynamic dispatch.

level is configuration-controlled, but typeof logger[level] === 'function' also accepts inherited callable properties such as constructor. Calling logger.constructor(output) can throw during startup, while values like toString silently avoid logging. Restrict dispatch to the documented logger levels plus the special silent value, then retain the warning fallback for invalid values.

Proposed fix
+const validLevels = new Set(['error', 'warn', 'info', 'verbose', 'debug', 'silly']);
+
-    if (typeof logger[level] === 'function') {
+    if (validLevels.has(level) && typeof logger[level] === 'function') {
       logger[level](output);
     } else {
       logger.warn(output);
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Determine the log level
const logLevels = (options && options.logLevels) || {};
let level = 'warn';
if (key && logLevels[`deprecation_${key}`]) {
level = logLevels[`deprecation_${key}`];
} else if (logLevels['deprecation']) {
level = logLevels['deprecation'];
}
if (level === 'silent') {
return;
}
// Compose message
let output = `DeprecationWarning: The Parse Server ${type} '${key}' `;
output += changeNewKey != null ? `is deprecated and will be ${keyAction} in a future version.` : '';
output += changeNewDefault
? `default will change to '${changeNewDefault}' in a future version.`
: '';
output += solution ? ` ${solution}` : '';
logger.warn(output);
if (typeof logger[level] === 'function') {
logger[level](output);
} else {
logger.warn(output);
}
// Determine the log level
const logLevels = (options && options.logLevels) || {};
const validLevels = new Set(['error', 'warn', 'info', 'verbose', 'debug', 'silly']);
let level = 'warn';
if (key && logLevels[`deprecation_${key}`]) {
level = logLevels[`deprecation_${key}`];
} else if (logLevels['deprecation']) {
level = logLevels['deprecation'];
}
if (level === 'silent') {
return;
}
// Compose message
let output = `DeprecationWarning: The Parse Server ${type} '${key}' `;
output += changeNewKey != null ? `is deprecated and will be ${keyAction} in a future version.` : '';
output += changeNewDefault
? `default will change to '${changeNewDefault}' in a future version.`
: '';
output += solution ? ` ${solution}` : '';
if (validLevels.has(level) && typeof logger[level] === 'function') {
logger[level](output);
} else {
logger.warn(output);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Deprecator/Deprecator.js` around lines 121 - 146, Restrict the
configuration-derived level in the deprecation logging flow to the documented
logger levels plus the special `silent` value before dynamic dispatch. Update
the `logger[level]` check to reject inherited or unsupported callable
properties, while preserving the early return for `silent` and the existing
`logger.warn(output)` fallback for invalid levels.

}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Options/Definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1599,4 +1599,9 @@ module.exports.LogLevels = {
help: 'Log level used by the Cloud Code Triggers `beforeSave`, `beforeDelete`, `beforeFind`, `beforeLogin` on success. Default is `info`. See [LogLevel](LogLevel.html) for available values.',
default: 'info',
},
deprecation: {
env: 'PARSE_SERVER_LOG_LEVELS_DEPRECATION',
help: 'Log level used for deprecation warnings. Default is `warn`. Set to `silent` to suppress all deprecations. You can also specify per-deprecation log levels by appending the option key, e.g., `deprecation_fileUpload`. See [LogLevel](LogLevel.html) for available values.',
default: 'warn',
},
};
1 change: 1 addition & 0 deletions src/Options/docs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,4 +954,8 @@ export interface LogLevels {
:DEFAULT: info
*/
signupUsernameTaken: ?string;
/* Log level used for deprecation warnings. Default is `warn`. Set to `silent` to suppress all deprecations. You can also specify per-deprecation log levels by appending the option key, e.g., `deprecation_fileUpload`. See [LogLevel](LogLevel.html) for available values.
:DEFAULT: warn
*/
deprecation: ?string;
}