Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bartolkaruza/1d79aef7542d6b6856f7e2dccbf50a93 to your computer and use it in GitHub Desktop.
Save bartolkaruza/1d79aef7542d6b6856f7e2dccbf50a93 to your computer and use it in GitHub Desktop.
Find file and line number for custom openbook error code
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