Skip to content

Instantly share code, notes, and snippets.

@ctavan
Created August 7, 2019 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctavan/2c83b68c301894ec09fb4dc456c8ad2e to your computer and use it in GitHub Desktop.
Save ctavan/2c83b68c301894ec09fb4dc456c8ad2e to your computer and use it in GitHub Desktop.
commit ********b2a5c668b54348d0f3f891ddc58ef9f8
Author: Christoph Tavan <christoph@contentpass.de>
Date: Mon Mar 11 16:53:10 2019 +0100
Fix sorting of error codes
Apparently with node 11 there's a subtle change in how array sorting
compare function return values are interpreted. According to the spec
the return value of 0 will not change the sorting. A negative return
value will sort the element below and must be used in this case.
It's interesting that a return value of 0 was behaving like a return
value of -1 in node 10 but behaves differently in node 11.
diff --git a/services/core/lib/common/error/ErrorCode.js b/services/core/lib/common/error/ErrorCode.js
index b7576ce1..d2bf712d 100644
--- a/services/core/lib/common/error/ErrorCode.js
+++ b/services/core/lib/common/error/ErrorCode.js
@@ -71,7 +71,7 @@ export default class ErrorCode {
// Required to make sure they already exist when instantiating
// error codes that reference them as their publicErrorCode.
function listPublicErrorsFirst(code) {
- return codes[code].publicErrorCode ? 1 : 0;
+ return codes[code].publicErrorCode ? 1 : -1;
}
Object.keys(codes).sort(listPublicErrorsFirst).forEach((code) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment