forked from deephaven/deephaven-plugins
-
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.
fix: Errors not visible when opening deephaven.ui widget
- Add an error listener to a command - WIP, does not actually display the error yet but is wired up to listen to it. - Need to pass the error down to `DocumentHandler`? Or have a separate `DocumentErrorHandler` widget?
- Loading branch information
Showing
4 changed files
with
116 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from enum import Enum | ||
|
||
|
||
class ErrorCode(int, Enum): | ||
""" | ||
ServerErrorCode is a list of error codes that can be returned by the server. Values are based on the JSON-RPC 2.0 | ||
specification. See https://www.jsonrpc.org/specification#error_object for more information. | ||
The range -32000 to -32099 are reserved for implementation-defined server-errors. | ||
""" | ||
|
||
# General errors | ||
UNKNOWN = -32600 | ||
""" | ||
An unknown error occurred on the server. | ||
""" | ||
|
||
RENDER_ERROR = -32601 | ||
""" | ||
There was an error when rendering the document. | ||
""" |
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,27 @@ | ||
import { JSONRPCErrorResponse, isJSONRPCResponse } from "json-rpc-2.0"; | ||
|
||
export function isJSONRPCErrorResponse(obj: unknown): obj is JSONRPCErrorResponse { | ||
return obj != null && isJSONRPCResponse(obj) && obj.error !== undefined; | ||
} | ||
|
||
/** | ||
* Parse the error payload to get a user-friendly error message. | ||
* @param error Error payload to parse. Should be a JSON-RPC error response object, an Error object, or a string. | ||
* @returns A string of the error message to display to the user. | ||
*/ | ||
export function parseServerErrorPayload(error: unknown): string { | ||
if (isJSONRPCErrorResponse(error)) { | ||
return error.error.message; | ||
} | ||
|
||
if (typeof error === 'string') { | ||
return error; | ||
} | ||
|
||
if (error instanceof Error) { | ||
return error.message; | ||
} | ||
|
||
|
||
return 'An unknown error occurred.'; | ||
} |
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