Created
May 5, 2023 07:24
-
-
Save bartolkaruza/1d79aef7542d6b6856f7e2dccbf50a93 to your computer and use it in GitHub Desktop.
Find file and line number for custom openbook error code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function decodeSerumErrorCode(customErrorCode) { | |
// Extract the line number (lower 16 bits) | |
const lineNumber = customErrorCode & 0xFFFF; | |
// Extract the source file ID (upper 8 bits) | |
const sourceFileId = (customErrorCode >> 24) & 0xFF; | |
// Map the source file ID to the corresponding file name | |
const sourceFileMap = { | |
1: "src/state.rs", | |
2: "src/matching.rs", | |
3: "src/critbit.rs", | |
}; | |
const fileName = sourceFileMap[sourceFileId] || "Unknown"; | |
return { | |
file: fileName, | |
line: lineNumber, | |
}; | |
} | |
// Example usage: | |
const customErrorCode = 0x10005f2; | |
const errorLocation = decodeSerumErrorCode(customErrorCode); | |
console.log(`Error in file: ${errorLocation.file}, line: ${errorLocation.line}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment