Skip to content

Commit 36262bd

Browse files
committed
feat: rollback lock file position, improve error messages
1 parent be839d8 commit 36262bd

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
on:
22
push:
33
tags:
4-
- "*"
4+
- '*'
55

66
name: Deploy Extension
77
jobs:

src/utils.ts

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import { commands, window } from 'vscode'
88
import { config } from './config'
99
import * as Meta from './generated/meta'
1010
import { log } from './logger'
11+
import { baseDir } from './path'
1112
import { restartApp } from './restart'
1213

1314
export const fileProtocol = 'file://'
1415
export const httpsProtocol = 'https://'
1516

16-
const lockFile = path.join(os.tmpdir(), `__${Meta.name}__.lock`)
17+
const lockFile = path.join(baseDir, `__${Meta.name}__.lock`)
1718

1819
let last = hasElectronWindowOptions()
1920
function hasElectronWindowOptions(): string {
@@ -49,44 +50,56 @@ export async function runAndRestart(message: string, fullRestart: boolean, actio
4950
return
5051
}
5152
}
53+
let success = true
5254
try {
5355
writeFileSync(lockFile, String(Date.now()))
54-
let success = true
5556
try {
5657
logWindowOptionsChanged(fullRestart)
5758
await action()
5859
} catch (error) {
5960
logError('Fail to execute action', error)
6061
success = false
62+
} finally {
63+
fs.rmSync(lockFile)
6164
}
62-
if (success) {
63-
let shouldProceed = false
64-
if (config.reloadWithoutPrompting) {
65-
shouldProceed = true
66-
} else {
67-
const item = await showMessage(
68-
message,
69-
fullRestart ? 'Restart APP' : 'Reload Window',
70-
'Cancel',
71-
)
72-
shouldProceed = item === 'Reload Window' || item === 'Restart APP'
65+
} catch (err) {
66+
if (err instanceof Error) {
67+
const base = 'This extension need to modify VSCode\'s source code but'
68+
if ('code' in err && err.code === 'EROFS') {
69+
logError(`${base} it runs on read-only filesystem. Maybe you need to choose another way to install VSCode`, err)
70+
return
71+
} else if (err.message.includes('RangeError: Maximum call stack size exceeded')) {
72+
logError(`${base} current user is not allowed. Please comfirm that you have the permission to write files in ${baseDir}`, err)
73+
return
7374
}
74-
if (shouldProceed) {
75-
if (fullRestart) {
76-
try {
77-
await restartApp()
78-
} catch (error) {
79-
logError('Fail to restart VSCode', error)
80-
}
81-
} else {
82-
commands.executeCommand('workbench.action.reloadWindow')
75+
}
76+
logError('Unknown error in npm:atomically', err)
77+
return
78+
}
79+
80+
if (success) {
81+
let shouldProceed = false
82+
if (config.reloadWithoutPrompting) {
83+
shouldProceed = true
84+
} else {
85+
const item = await showMessage(
86+
message,
87+
fullRestart ? 'Restart APP' : 'Reload Window',
88+
'Cancel',
89+
)
90+
shouldProceed = item === 'Reload Window' || item === 'Restart APP'
91+
}
92+
if (shouldProceed) {
93+
if (fullRestart) {
94+
try {
95+
await restartApp()
96+
} catch (error) {
97+
logError('Fail to restart VSCode', error)
8398
}
99+
} else {
100+
commands.executeCommand('workbench.action.reloadWindow')
84101
}
85102
}
86-
} catch (e) {
87-
logError(`npm:atomically error, maybe you need to enhance VSCode's permissions?`, e)
88-
} finally {
89-
fs.rmSync(lockFile)
90103
}
91104
}
92105

0 commit comments

Comments
 (0)