Skip to content

Commit 3223aed

Browse files
committed
fix: try to replace existing config with old schema; try to copy the existing config to a backup file
maybe risky, but printing: hope to make a better solution in the future
1 parent fbf0be7 commit 3223aed

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/common/config.nim

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## keep this in sync with types.nim Config def
22
## a file with config code for the c backend, used mostly by ui_data for repl/tests
33

4-
import json_serialization/std/tables, strutils, sequtils, os, yaml, std/streams
4+
import json_serialization/std/tables, strutils, sequtils, os, yaml, std / [streams, strformat]
55
import .. / common / [types, paths]
66

77
type
@@ -139,7 +139,7 @@ proc loadConfig*(folder: string, inTest: bool): Config =
139139
if file.len == 0:
140140
file = userConfigDir / configPath
141141
createDir(userConfigDir)
142-
copyFile(configDir / defaultConfigPath, userConfigDir / configPath)
142+
copyFile(configDir / defaultConfigPath, file)
143143
# if inTest:
144144
# file = codetracerTestDir / testConfigPath
145145
var raw = ""
@@ -160,6 +160,15 @@ proc loadConfig*(folder: string, inTest: bool): Config =
160160
except Exception as e:
161161
echo "ERROR: loading config: ", e.msg
162162
echo " if the schema has changed, and you have an existing config file, you might get an error here"
163-
echo " you can manually adapt your config file or"
164-
echo " you can reset it by deleting $HOME/.config/codetracer/.config.yaml"
165-
quit(1)
163+
# echo " you can manually adapt your config file or"
164+
# echo " you can reset it by deleting $HOME/.config/codetracer/.config.yaml"
165+
let backupFilePath = userConfigDir / "backup_config.yaml"
166+
createDir(userConfigDir)
167+
try:
168+
copyFile(file, backupFilePath)
169+
echo fmt" for now we now have directly copied your existing config file to {backupFilePath}"
170+
except Exception as copyError:
171+
echo "ERROR: couldn't backup your existing config file; error: ", copyError.msg
172+
copyFile(configDir / defaultConfigPath, file)
173+
echo " REPLACED with new up to date default config file"
174+

0 commit comments

Comments
 (0)