-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
96 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Logger } from './Logger'; | ||
|
||
const logger = new Logger('errorUtils'); | ||
|
||
export interface ParsedError { | ||
[key: string]: string | number | undefined; | ||
type?: string; | ||
value?: string; | ||
line?: number; | ||
namespace?: string; | ||
file?: string; | ||
traceback?: string; | ||
} | ||
|
||
/** | ||
* Parse a server error string into a key-value object. | ||
* @param error | ||
*/ | ||
export function parseServerError(error: string): ParsedError { | ||
const errorDetails: ParsedError = {}; | ||
const lines = error.split('\n'); | ||
|
||
if (lines[0] !== 'java.lang.RuntimeException: Error in Python interpreter:') { | ||
logger.debug('Unrecognized error type:', error); | ||
return errorDetails; | ||
} | ||
|
||
while (lines.length) { | ||
const line = lines.shift()!; | ||
|
||
const [key, value] = line.split(':'); | ||
|
||
if (key && value) { | ||
// Once we hit the Traceback, accumulate remaining lines | ||
if (key === 'Traceback (most recent call last)') { | ||
errorDetails.traceback = [value, ...lines].join('\n'); | ||
break; | ||
} | ||
|
||
errorDetails[key.toLowerCase()] = | ||
key === 'Line' ? Number(value.trim()) : value.trim(); | ||
} | ||
} | ||
|
||
return errorDetails; | ||
} |
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