@lvce-editor/pty-host 0.18.11 → 0.18.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/pty-host",
3
- "version": "0.18.11",
3
+ "version": "0.18.13",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  "node": ">=16"
17
17
  },
18
18
  "dependencies": {
19
- "@lvce-editor/pretty-error": "^1.2.0",
19
+ "@lvce-editor/pretty-error": "^1.2.1",
20
20
  "@lvce-editor/verror": "^1.1.1",
21
21
  "debug": "^4.3.4",
22
22
  "ws": "^8.14.2"
@@ -0,0 +1,11 @@
1
+ export const Backslash = '\\'
2
+ export const Dash = '-'
3
+ export const Dot = '.'
4
+ export const EmptyString = ''
5
+ export const NewLine = '\n'
6
+ export const OpenAngleBracket = '<'
7
+ export const Slash = '/'
8
+ export const Space = ' '
9
+ export const Tab = '\t'
10
+ export const Underline = '_'
11
+ export const T = 't'
@@ -0,0 +1,64 @@
1
+ import * as Character from '../Character/Character.js'
2
+ import * as ExitCode from '../ExitCode/ExitCode.js'
3
+ import * as GetNewLineIndex from '../GetNewLineIndex/GetNewLineIndex.js'
4
+ import * as IsIgnoredError from '../IsIgnoredError/IsIgnoredError.js'
5
+ import * as Logger from '../Logger/Logger.js'
6
+ import * as PrettyError from '../PrettyError/PrettyError.js'
7
+ import * as Process from '../Process/Process.js'
8
+
9
+ export const state = {
10
+ seenErrors: [],
11
+ }
12
+
13
+ const preparePrettyError = (error) => {
14
+ const cause = error.cause()
15
+ return {
16
+ message: error.message,
17
+ codeFrame: cause.codeFrame,
18
+ stack: cause.stack,
19
+ }
20
+ }
21
+
22
+ const printPrettyError = (prettyError) => {
23
+ console.error(`${prettyError.message}\n${prettyError.codeFrame}\n${prettyError.stack}`)
24
+ }
25
+
26
+ export const handleError = (error) => {
27
+ if (state.seenErrors.includes(error.message)) {
28
+ return
29
+ }
30
+ state.seenErrors.push(error.message)
31
+ const prettyError = preparePrettyError(error)
32
+ // Socket.send({
33
+ // jsonrpc: JsonRpcVersion.Two,
34
+ // method: /* Dialog.showErrorDialogWithOptions */ 'Dialog.showMessage',
35
+ // params: [
36
+ // {
37
+ // message: prettyError.message,
38
+ // codeFrame: prettyError.codeFrame,
39
+ // stack: prettyError.stack,
40
+ // },
41
+ // ],
42
+ // })
43
+ printPrettyError(prettyError)
44
+ }
45
+
46
+ const firstErrorLine = (error) => {
47
+ if (error.stack) {
48
+ return error.stack.slice(0, GetNewLineIndex.getNewLineIndex(error.stack))
49
+ }
50
+ if (error.message) {
51
+ return error.message
52
+ }
53
+ return `${error}`
54
+ }
55
+
56
+ export const handleUncaughtExceptionMonitor = (error, origin) => {
57
+ Logger.info(`[pty host] uncaught exception: ${firstErrorLine(error)}`)
58
+ if (IsIgnoredError.isIgnoredError(error)) {
59
+ return
60
+ }
61
+ const prettyError = PrettyError.prepare(error)
62
+ Logger.error(prettyError.codeFrame + Character.NewLine + prettyError.stack + Character.NewLine)
63
+ Process.setExitCode(ExitCode.Error)
64
+ }
@@ -0,0 +1,5 @@
1
+ export const Error = 1
2
+
3
+ export const ExpectedError = 128
4
+
5
+ export const Success = 0
@@ -0,0 +1,11 @@
1
+ import * as Character from '../Character/Character.js'
2
+
3
+ /**
4
+ *
5
+ * @param {string} string
6
+ * @param {number|undefined} startIndex
7
+ * @returns
8
+ */
9
+ export const getNewLineIndex = (string, startIndex = undefined) => {
10
+ return string.indexOf(Character.NewLine, startIndex)
11
+ }
@@ -0,0 +1,14 @@
1
+ import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
+ import * as Process from '../Process/Process.js'
3
+
4
+ export const isIgnoredError = (error) => {
5
+ if (error && error.code === ErrorCodes.EPIPE && !process.connected) {
6
+ // parent process is disposed, ignore
7
+ return true
8
+ }
9
+ if (error && error.code === ErrorCodes.ERR_IPC_CHANNEL_CLOSED && !Process.isConnected()) {
10
+ // parent process is disposed, ignore
11
+ return true
12
+ }
13
+ return false
14
+ }
@@ -3,8 +3,10 @@ import * as CommandState from '../CommandState/CommandState.js'
3
3
  import * as HandleIpc from '../HandleIpc/HandleIpc.js'
4
4
  import * as IpcChild from '../IpcChild/IpcChild.js'
5
5
  import * as IpcChildType from '../IpcChildType/IpcChildType.js'
6
+ import * as ProcessListeners from '../ProcessListeners/ProcessListeners.js'
6
7
 
7
8
  export const main = async () => {
9
+ process.on('uncaughtExceptionMonitor', ProcessListeners.handleUncaughtExceptionMonitor)
8
10
  CommandState.registerCommands(CommandMap.commandMap)
9
11
  const ipc = await IpcChild.listen({ method: IpcChildType.Auto() })
10
12
  HandleIpc.handleIpc(ipc)
@@ -0,0 +1,17 @@
1
+ export const exit = (code) => {
2
+ process.exit(code)
3
+ }
4
+
5
+ export const setExitCode = (exitCode) => {
6
+ process.exitCode = exitCode
7
+ }
8
+
9
+ export const { argv } = process
10
+
11
+ export const isConnected = () => {
12
+ return process.connected
13
+ }
14
+
15
+ export const getPid = () => {
16
+ return process.pid
17
+ }
@@ -0,0 +1,17 @@
1
+ import * as ErrorHandling from '../ErrorHandling/ErrorHandling.js'
2
+ import * as ExitCode from '../ExitCode/ExitCode.js'
3
+ import * as Process from '../Process/Process.js'
4
+
5
+ export const handleDisconnect = () => {
6
+ console.info('[pty host] disconnected')
7
+ Process.exit(ExitCode.Success)
8
+ }
9
+
10
+ export const handleSigTerm = () => {
11
+ console.info('[pty host] sigterm')
12
+ Process.exit(ExitCode.Success)
13
+ }
14
+
15
+ export const handleUncaughtExceptionMonitor = (error) => {
16
+ ErrorHandling.handleUncaughtExceptionMonitor(error)
17
+ }